Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

login instead of email on frontend has been implemented #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function removeLocalData() {

export default function Component() {
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [email, setEmail] = useState<string>("");
const [name, setEmail] = useState<string>("");
const [password, setPassword] = useState<string>("");
const router = useRouter();
const { t } = useTranslation(); // Use translation hook for localization
Expand All @@ -31,15 +31,15 @@ export default function Component() {
const response = await axios.post(
`/api/v1/auth/login`,
{
email,
name,
password,
}
);

if (response.status === 200) {
// Save the token in local storage for future requests
localStorage.setItem("authToken", response.data.token);
localStorage.setItem("email", email);
localStorage.setItem("name", name);
// Redirect to the home page
router.push("/");
}
Expand All @@ -48,8 +48,8 @@ export default function Component() {
setTimeout(() => {
setErrorMessage(null);
}, 2000);
// Set the focus to the email input field
document.getElementById("email")?.focus();
// Set the focus to the name input field
document.getElementById("name")?.focus();
}
};

Expand Down Expand Up @@ -85,13 +85,13 @@ export default function Component() {
</div>
)}
<div className="space-y-2">
<Label htmlFor="email">{t("login.email")}</Label>
<Label htmlFor="name">{t("login.name")}</Label>
<Input
id="email"
id="name"
placeholder={t("login.emailPlaceholder")}
required
type="email"
value={email}
type="name"
value={name}
onChange={(e) => setEmail(e.target.value)}
onKeyDown={handleKeyDown}
/>
Expand Down
8 changes: 4 additions & 4 deletions app/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export default function Component() {
window.location.href = '/login'; // Redirect to the login page (where the authToken is cleared)
}

// TODO: Make it more robust by fetching the email by API, not storing it in local storage
// TODO: Make it more robust by fetching the name by API, not storing it in local storage
const getEmail = (): string => {
if (typeof window !== 'undefined') {
const email = localStorage.getItem('email'); // Safe to use localStorage here
if (email) return email;
const name = localStorage.getItem('name'); // Safe to use localStorage here
if (name) return name;
}
return 'Email not found';
return 'name';
};

return (
Expand Down
6 changes: 3 additions & 3 deletions lib/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@
},
"login": {
"title": "Anmeldung",
"description": "Geben Sie Ihre E-Mail-Adresse und Ihr Passwort ein, um sich bei Ihrem Konto anzumelden",
"email": "E-Mail",
"emailPlaceholder": "Ihre E-Mail-Adresse",
"description": "Geben Sie Ihre Name und Ihr Passwort ein, um sich bei Ihrem Konto anzumelden",
"name": "Name",
"emailPlaceholder": "Ihre Name",
"password": "Passwort",
"passwordPlaceholder": "Ihr Passwort",
"loginButton": "Anmelden"
Expand Down
6 changes: 3 additions & 3 deletions lib/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@
},
"login": {
"title": "Login",
"description": "Enter your email and password to login to your account",
"email": "Email",
"emailPlaceholder": "Your email address",
"description": "Enter your name and password to login to your account",
"name": "Name",
"emailPlaceholder": "Your name",
"password": "Password",
"passwordPlaceholder": "Your password",
"loginButton": "Login"
Expand Down