|
1 | 1 | 'use client'; |
2 | 2 |
|
3 | | -import React, { useState } from 'react'; |
4 | | -import { signIn } from 'next-auth/react'; |
5 | | -import { useRouter } from 'next/navigation'; |
6 | 3 | import { Button } from '@infinum/ui/components/button'; |
7 | | -import { Label } from '@infinum/ui/components/label'; |
8 | 4 | import { Input } from '@infinum/ui/components/input'; |
| 5 | +import { Label } from '@infinum/ui/components/label'; |
| 6 | +import { signIn } from 'next-auth/react'; |
| 7 | +import { useLocale } from 'next-intl'; |
| 8 | +import React, { useState } from 'react'; |
9 | 9 |
|
10 | 10 | export const LoginForm = () => { |
11 | 11 | const [email, setEmail] = useState(''); |
12 | 12 | const [password, setPassword] = useState(''); |
13 | 13 | const [error, setError] = useState(''); |
14 | | - const router = useRouter(); |
| 14 | + const locale = useLocale(); |
15 | 15 |
|
16 | 16 | const handleSubmit = async (e: React.FormEvent) => { |
17 | 17 | e.preventDefault(); |
18 | 18 | setError(''); |
19 | 19 |
|
20 | 20 | const res = await signIn('credentials', { |
21 | | - redirect: false, |
| 21 | + redirect: true, |
22 | 22 | email, |
23 | 23 | password, |
| 24 | + callbackUrl: `/${locale}`, |
24 | 25 | }); |
25 | 26 |
|
26 | 27 | if (res?.error) { |
27 | 28 | setError(res.error); |
28 | | - } else { |
29 | | - router.push('/'); |
30 | 29 | } |
31 | 30 | }; |
32 | 31 |
|
33 | 32 | return ( |
34 | 33 | <form onSubmit={handleSubmit} className="space-y-6"> |
35 | 34 | <div> |
36 | 35 | <Label htmlFor="email">EMail</Label> |
37 | | - <Input id="email" type="email" value={email} onChange={(e) => setEmail(e.target.value)} required /> |
| 36 | + <Input |
| 37 | + id="email" |
| 38 | + type="email" |
| 39 | + value={email} |
| 40 | + onChange={(e) => setEmail(e.target.value)} |
| 41 | + autoComplete="email" |
| 42 | + required |
| 43 | + /> |
38 | 44 | </div> |
39 | 45 |
|
40 | 46 | <div> |
41 | 47 | <Label htmlFor="password">Password</Label> |
42 | | - <Input id="password" type="password" value={password} onChange={(e) => setPassword(e.target.value)} required /> |
| 48 | + <Input |
| 49 | + id="password" |
| 50 | + type="password" |
| 51 | + value={password} |
| 52 | + onChange={(e) => setPassword(e.target.value)} |
| 53 | + autoComplete="current-password" |
| 54 | + required |
| 55 | + /> |
43 | 56 | </div> |
44 | 57 |
|
45 | 58 | {error && <p className="text-sm text-red-500">{error}</p>} |
|
0 commit comments