generator-kodly-react-app 1.0.15 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/generators/app/index.js +4 -0
- package/generators/app/templates/I18N_MIGRATION.md +13 -13
- package/generators/app/templates/STRUCTURE.md +26 -26
- package/generators/app/templates/index.html +6 -14
- package/generators/app/templates/openapi-ts.config.ts +12 -12
- package/generators/app/templates/postcss.config.js +0 -1
- package/generators/app/templates/src/app.tsx +20 -20
- package/generators/app/templates/src/components/layout/language-switcher.tsx +20 -16
- package/generators/app/templates/src/components/layout/page-layout.tsx +31 -0
- package/generators/app/templates/src/components/layout/theme-switcher.tsx +15 -14
- package/generators/app/templates/src/components/theme/theme-provider.tsx +20 -13
- package/generators/app/templates/src/components/ui/button.tsx +15 -14
- package/generators/app/templates/src/components/ui/card.tsx +23 -16
- package/generators/app/templates/src/components/ui/field.tsx +35 -35
- package/generators/app/templates/src/components/ui/form.tsx +66 -30
- package/generators/app/templates/src/components/ui/input-group.tsx +24 -24
- package/generators/app/templates/src/components/ui/input.tsx +8 -8
- package/generators/app/templates/src/components/ui/label.tsx +9 -9
- package/generators/app/templates/src/components/ui/select.tsx +0 -1
- package/generators/app/templates/src/components/ui/separator.tsx +10 -10
- package/generators/app/templates/src/components/ui/textarea.tsx +7 -7
- package/generators/app/templates/src/index.css +12 -2
- package/generators/app/templates/src/lib/i18n.ts +16 -14
- package/generators/app/templates/src/lib/routes.ts +2 -3
- package/generators/app/templates/src/lib/utils/error-handler.ts +21 -14
- package/generators/app/templates/src/lib/utils.ts +3 -3
- package/generators/app/templates/src/locales/index.ts +12 -12
- package/generators/app/templates/src/locales/ja/theme.json +0 -1
- package/generators/app/templates/src/main.tsx +10 -12
- package/generators/app/templates/src/modules/app/layouts/app-layout.tsx +14 -25
- package/generators/app/templates/src/modules/app/locales/app-en.json +0 -1
- package/generators/app/templates/src/modules/app/locales/app-ja.json +0 -1
- package/generators/app/templates/src/modules/auth/components/auth-form.tsx +83 -0
- package/generators/app/templates/src/modules/auth/components/forgot-password-form.tsx +27 -52
- package/generators/app/templates/src/modules/auth/components/login-form.tsx +42 -72
- package/generators/app/templates/src/modules/auth/components/login-link.tsx +12 -0
- package/generators/app/templates/src/modules/auth/components/reset-password-form.tsx +46 -92
- package/generators/app/templates/src/modules/auth/components/signup-form.tsx +35 -71
- package/generators/app/templates/src/modules/auth/contexts/auth-context.tsx +10 -6
- package/generators/app/templates/src/modules/auth/hooks/use-auth-hook.ts +51 -36
- package/generators/app/templates/src/modules/auth/layouts/auth-layout.tsx +12 -15
- package/generators/app/templates/src/modules/auth/locales/auth-en.json +0 -1
- package/generators/app/templates/src/modules/auth/locales/auth-ja.json +0 -1
- package/generators/app/templates/src/modules/auth/schemas/form-schemas.ts +14 -10
- package/generators/app/templates/src/modules/landing/components/auth-hero.tsx +20 -18
- package/generators/app/templates/src/modules/landing/components/welcome-hero.tsx +13 -11
- package/generators/app/templates/src/modules/landing/landing-page-layout.tsx +1 -24
- package/generators/app/templates/src/modules/landing/landing-page.tsx +11 -6
- package/generators/app/templates/src/modules/landing/layouts/landing-page-layout.tsx +2 -21
- package/generators/app/templates/src/modules/landing/locales/landing-en.json +0 -1
- package/generators/app/templates/src/openapi-client-config.ts +1 -1
- package/generators/app/templates/src/routeTree.gen.ts +188 -188
- package/generators/app/templates/src/router.tsx +2 -2
- package/generators/app/templates/src/routes/$.tsx +0 -1
- package/generators/app/templates/src/routes/__root.tsx +2 -2
- package/generators/app/templates/src/routes/_landing/index.tsx +3 -3
- package/generators/app/templates/src/routes/_landing/route.tsx +3 -3
- package/generators/app/templates/src/routes/app/index.tsx +6 -6
- package/generators/app/templates/src/routes/app/route.tsx +4 -4
- package/generators/app/templates/src/routes/auth/forgot-password.tsx +1 -1
- package/generators/app/templates/src/routes/auth/login.tsx +3 -3
- package/generators/app/templates/src/routes/auth/reset-password.tsx +3 -3
- package/generators/app/templates/src/routes/auth/route.tsx +12 -7
- package/generators/app/templates/src/routes/auth/signup.tsx +1 -2
- package/generators/app/templates/src/sdk/@tanstack/react-query.gen.ts +157 -76
- package/generators/app/templates/src/sdk/client/client.gen.ts +35 -37
- package/generators/app/templates/src/sdk/client/index.ts +8 -8
- package/generators/app/templates/src/sdk/client/types.gen.ts +22 -19
- package/generators/app/templates/src/sdk/client/utils.gen.ts +53 -45
- package/generators/app/templates/src/sdk/client.gen.ts +18 -5
- package/generators/app/templates/src/sdk/core/auth.gen.ts +6 -6
- package/generators/app/templates/src/sdk/core/bodySerializer.gen.ts +25 -27
- package/generators/app/templates/src/sdk/core/params.gen.ts +12 -12
- package/generators/app/templates/src/sdk/core/pathSerializer.gen.ts +40 -41
- package/generators/app/templates/src/sdk/core/queryKeySerializer.gen.ts +12 -29
- package/generators/app/templates/src/sdk/core/serverSentEvents.gen.ts +26 -24
- package/generators/app/templates/src/sdk/core/types.gen.ts +17 -15
- package/generators/app/templates/src/sdk/core/utils.gen.ts +18 -18
- package/generators/app/templates/src/sdk/index.ts +40 -2
- package/generators/app/templates/src/sdk/schemas.gen.ts +108 -166
- package/generators/app/templates/src/sdk/sdk.gen.ts +145 -63
- package/generators/app/templates/src/sdk/types.gen.ts +90 -84
- package/generators/app/templates/src/sdk/zod.gen.ts +57 -74
- package/generators/app/templates/src/types/i18n.d.ts +0 -1
- package/generators/app/templates/tailwind.config.js +0 -1
- package/generators/app/templates/tsconfig.app.json +0 -1
- package/generators/app/templates/tsconfig.json +0 -1
- package/generators/app/templates/tsr.config.json +4 -0
- package/generators/app/templates/vite.config.js +12 -12
- package/package.json +2 -4
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { Route as ForgotPasswordRoute } from '@/routes/auth/forgot-password';
|
|
13
|
-
import { loginFormDefaults } from '@/modules/auth/schemas/form-schemas';
|
|
1
|
+
import { AuthForm } from "./auth-form";
|
|
2
|
+
import { useLogin } from "@/modules/auth/hooks/use-auth-hook";
|
|
3
|
+
import { zUserLoginDto } from "@/sdk/zod.gen";
|
|
4
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
5
|
+
import { useForm } from "react-hook-form";
|
|
6
|
+
import { useTranslation } from "react-i18next";
|
|
7
|
+
import type { z } from "zod";
|
|
8
|
+
import { Link } from "@tanstack/react-router";
|
|
9
|
+
import { Route as SignupRoute } from "@/routes/auth/signup";
|
|
10
|
+
import { Route as ForgotPasswordRoute } from "@/routes/auth/forgot-password";
|
|
11
|
+
import { loginFormDefaults } from "@/modules/auth/schemas/form-schemas";
|
|
14
12
|
|
|
15
13
|
type LoginFormData = z.infer<typeof zUserLoginDto>;
|
|
16
14
|
|
|
@@ -27,69 +25,41 @@ export function LoginForm() {
|
|
|
27
25
|
};
|
|
28
26
|
|
|
29
27
|
return (
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
/>
|
|
56
|
-
<FormField
|
|
57
|
-
control={form.control}
|
|
58
|
-
name='password'
|
|
59
|
-
render={({ field }) => (
|
|
60
|
-
<FormItem>
|
|
61
|
-
<FormLabel>{t('auth.login.password')} *</FormLabel>
|
|
62
|
-
<FormControl>
|
|
63
|
-
<Input
|
|
64
|
-
type='password'
|
|
65
|
-
placeholder={t('auth.login.passwordPlaceholder')}
|
|
66
|
-
autoComplete='current-password'
|
|
67
|
-
{...field}
|
|
68
|
-
/>
|
|
69
|
-
</FormControl>
|
|
70
|
-
<FormMessage />
|
|
71
|
-
</FormItem>
|
|
72
|
-
)}
|
|
73
|
-
/>
|
|
74
|
-
<Button
|
|
75
|
-
type='submit'
|
|
76
|
-
disabled={isPending}>
|
|
77
|
-
{t('auth.login.submit')}
|
|
78
|
-
</Button>
|
|
79
|
-
</form>
|
|
80
|
-
</Form>
|
|
81
|
-
<div className='flex flex-col gap-2 text-sm text-center'>
|
|
28
|
+
<AuthForm
|
|
29
|
+
form={form}
|
|
30
|
+
title={t("auth.login.title")}
|
|
31
|
+
onSubmit={onSubmit}
|
|
32
|
+
isPending={isPending}
|
|
33
|
+
submitLabel={t("auth.login.submit")}
|
|
34
|
+
fields={[
|
|
35
|
+
{
|
|
36
|
+
name: "email",
|
|
37
|
+
label: t("auth.login.email"),
|
|
38
|
+
placeholder: t("auth.login.emailPlaceholder"),
|
|
39
|
+
type: "email",
|
|
40
|
+
autoComplete: "email",
|
|
41
|
+
autoFocus: true,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "password",
|
|
45
|
+
label: t("auth.login.password"),
|
|
46
|
+
placeholder: t("auth.login.passwordPlaceholder"),
|
|
47
|
+
type: "password",
|
|
48
|
+
autoComplete: "current-password",
|
|
49
|
+
},
|
|
50
|
+
]}
|
|
51
|
+
>
|
|
52
|
+
<div className="flex flex-col gap-2 text-sm text-center">
|
|
82
53
|
<Link
|
|
83
54
|
to={ForgotPasswordRoute.to}
|
|
84
|
-
className=
|
|
85
|
-
|
|
55
|
+
className="text-primary hover:underline"
|
|
56
|
+
>
|
|
57
|
+
{t("auth.login.forgotPasswordLink")}
|
|
86
58
|
</Link>
|
|
87
|
-
<Link
|
|
88
|
-
|
|
89
|
-
className='text-primary hover:underline'>
|
|
90
|
-
{t('auth.login.signupLink')}
|
|
59
|
+
<Link to={SignupRoute.to} className="text-primary hover:underline">
|
|
60
|
+
{t("auth.login.signupLink")}
|
|
91
61
|
</Link>
|
|
92
62
|
</div>
|
|
93
|
-
</
|
|
63
|
+
</AuthForm>
|
|
94
64
|
);
|
|
95
65
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Link } from "@tanstack/react-router";
|
|
2
|
+
import { Route as LoginRoute } from "@/routes/auth/login";
|
|
3
|
+
|
|
4
|
+
export function LoginLink({ label }: { label: string }) {
|
|
5
|
+
return (
|
|
6
|
+
<div className="text-sm text-center">
|
|
7
|
+
<Link to={LoginRoute.to} className="text-primary hover:underline">
|
|
8
|
+
{label}
|
|
9
|
+
</Link>
|
|
10
|
+
</div>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import { Route as LoginRoute } from '@/routes/auth/login';
|
|
12
|
-
import { resetPasswordFormDefaults } from '@/modules/auth/schemas/form-schemas';
|
|
1
|
+
import { AuthForm } from "./auth-form";
|
|
2
|
+
import { useResetPassword } from "@/modules/auth/hooks/use-auth-hook";
|
|
3
|
+
import { zUserResetPasswordDto } from "@/sdk/zod.gen";
|
|
4
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
5
|
+
import { useForm } from "react-hook-form";
|
|
6
|
+
import { useTranslation } from "react-i18next";
|
|
7
|
+
import type { z } from "zod";
|
|
8
|
+
import { useSearch } from "@tanstack/react-router";
|
|
9
|
+
import { LoginLink } from "./login-link";
|
|
10
|
+
import { resetPasswordFormDefaults } from "@/modules/auth/schemas/form-schemas";
|
|
13
11
|
|
|
14
12
|
type ResetPasswordFormData = z.infer<typeof zUserResetPasswordDto>;
|
|
15
13
|
|
|
16
14
|
export function ResetPasswordForm() {
|
|
17
15
|
const { t } = useTranslation();
|
|
18
16
|
const { mutate, isPending } = useResetPassword();
|
|
19
|
-
const search = useSearch({ from:
|
|
17
|
+
const search = useSearch({ from: "/auth/reset-password" });
|
|
20
18
|
const form = useForm<ResetPasswordFormData>({
|
|
21
19
|
resolver: zodResolver(zUserResetPasswordDto),
|
|
22
20
|
defaultValues: {
|
|
23
21
|
...resetPasswordFormDefaults,
|
|
24
|
-
email: search.email ||
|
|
22
|
+
email: search.email || "",
|
|
25
23
|
},
|
|
26
24
|
});
|
|
27
25
|
|
|
@@ -30,83 +28,39 @@ export function ResetPasswordForm() {
|
|
|
30
28
|
};
|
|
31
29
|
|
|
32
30
|
return (
|
|
33
|
-
<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
type='text'
|
|
68
|
-
placeholder={t('auth.resetPassword.otpPlaceholder')}
|
|
69
|
-
autoComplete='one-time-code'
|
|
70
|
-
autoFocus
|
|
71
|
-
{...field}
|
|
72
|
-
/>
|
|
73
|
-
</FormControl>
|
|
74
|
-
<FormMessage />
|
|
75
|
-
</FormItem>
|
|
76
|
-
)}
|
|
77
|
-
/>
|
|
78
|
-
<FormField
|
|
79
|
-
control={form.control}
|
|
80
|
-
name='password'
|
|
81
|
-
render={({ field }) => (
|
|
82
|
-
<FormItem>
|
|
83
|
-
<FormLabel>{t('auth.resetPassword.password')} *</FormLabel>
|
|
84
|
-
<FormControl>
|
|
85
|
-
<Input
|
|
86
|
-
type='password'
|
|
87
|
-
placeholder={t('auth.resetPassword.passwordPlaceholder')}
|
|
88
|
-
autoComplete='new-password'
|
|
89
|
-
{...field}
|
|
90
|
-
/>
|
|
91
|
-
</FormControl>
|
|
92
|
-
<FormMessage />
|
|
93
|
-
</FormItem>
|
|
94
|
-
)}
|
|
95
|
-
/>
|
|
96
|
-
<Button
|
|
97
|
-
type='submit'
|
|
98
|
-
disabled={isPending}>
|
|
99
|
-
{t('auth.resetPassword.submit')}
|
|
100
|
-
</Button>
|
|
101
|
-
</form>
|
|
102
|
-
</Form>
|
|
103
|
-
<div className='text-sm text-center'>
|
|
104
|
-
<Link
|
|
105
|
-
to={LoginRoute.to}
|
|
106
|
-
className='text-primary hover:underline'>
|
|
107
|
-
{t('auth.forgotPassword.loginLink')}
|
|
108
|
-
</Link>
|
|
109
|
-
</div>
|
|
110
|
-
</div>
|
|
31
|
+
<AuthForm
|
|
32
|
+
form={form}
|
|
33
|
+
title={t("auth.resetPassword.title")}
|
|
34
|
+
onSubmit={onSubmit}
|
|
35
|
+
isPending={isPending}
|
|
36
|
+
submitLabel={t("auth.resetPassword.submit")}
|
|
37
|
+
fields={[
|
|
38
|
+
{
|
|
39
|
+
name: "email",
|
|
40
|
+
label: t("auth.resetPassword.email"),
|
|
41
|
+
placeholder: t("auth.resetPassword.emailPlaceholder"),
|
|
42
|
+
type: "email",
|
|
43
|
+
autoComplete: "email",
|
|
44
|
+
readOnly: true,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "otp",
|
|
48
|
+
label: t("auth.resetPassword.otp"),
|
|
49
|
+
placeholder: t("auth.resetPassword.otpPlaceholder"),
|
|
50
|
+
type: "text",
|
|
51
|
+
autoComplete: "one-time-code",
|
|
52
|
+
autoFocus: true,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "password",
|
|
56
|
+
label: t("auth.resetPassword.password"),
|
|
57
|
+
placeholder: t("auth.resetPassword.passwordPlaceholder"),
|
|
58
|
+
type: "password",
|
|
59
|
+
autoComplete: "new-password",
|
|
60
|
+
},
|
|
61
|
+
]}
|
|
62
|
+
>
|
|
63
|
+
<LoginLink label={t("auth.forgotPassword.loginLink")} />
|
|
64
|
+
</AuthForm>
|
|
111
65
|
);
|
|
112
66
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { Route as LoginRoute } from '@/routes/auth/login';
|
|
11
|
-
import { z } from 'zod';
|
|
12
|
-
import { signupFormDefaults } from '@/modules/auth/schemas/form-schemas';
|
|
1
|
+
import { AuthForm } from "./auth-form";
|
|
2
|
+
import { useSignup } from "@/modules/auth/hooks/use-auth-hook";
|
|
3
|
+
import { zUserSignupDto } from "@/sdk/zod.gen";
|
|
4
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
5
|
+
import { useForm } from "react-hook-form";
|
|
6
|
+
import { useTranslation } from "react-i18next";
|
|
7
|
+
import { LoginLink } from "./login-link";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { signupFormDefaults } from "@/modules/auth/schemas/form-schemas";
|
|
13
10
|
|
|
14
11
|
type SignupFormData = z.infer<typeof zUserSignupDto>;
|
|
15
12
|
|
|
@@ -29,64 +26,31 @@ export function SignupForm() {
|
|
|
29
26
|
};
|
|
30
27
|
|
|
31
28
|
return (
|
|
32
|
-
<
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
<FormField
|
|
59
|
-
control={form.control}
|
|
60
|
-
name='password'
|
|
61
|
-
render={({ field }) => (
|
|
62
|
-
<FormItem>
|
|
63
|
-
<FormLabel>{t('auth.signup.password')} *</FormLabel>
|
|
64
|
-
<FormControl>
|
|
65
|
-
<Input
|
|
66
|
-
type='password'
|
|
67
|
-
placeholder={t('auth.signup.passwordPlaceholder')}
|
|
68
|
-
autoComplete='new-password'
|
|
69
|
-
{...field}
|
|
70
|
-
/>
|
|
71
|
-
</FormControl>
|
|
72
|
-
<FormMessage />
|
|
73
|
-
</FormItem>
|
|
74
|
-
)}
|
|
75
|
-
/>
|
|
76
|
-
<Button
|
|
77
|
-
type='submit'
|
|
78
|
-
disabled={isPending}>
|
|
79
|
-
{t('auth.signup.submit')}
|
|
80
|
-
</Button>
|
|
81
|
-
</form>
|
|
82
|
-
</Form>
|
|
83
|
-
<div className='text-sm text-center'>
|
|
84
|
-
<Link
|
|
85
|
-
to={LoginRoute.to}
|
|
86
|
-
className='text-primary hover:underline'>
|
|
87
|
-
{t('auth.signup.loginLink')}
|
|
88
|
-
</Link>
|
|
89
|
-
</div>
|
|
90
|
-
</div>
|
|
29
|
+
<AuthForm
|
|
30
|
+
form={form}
|
|
31
|
+
title={t("auth.signup.title")}
|
|
32
|
+
onSubmit={onSubmit}
|
|
33
|
+
isPending={isPending}
|
|
34
|
+
submitLabel={t("auth.signup.submit")}
|
|
35
|
+
fields={[
|
|
36
|
+
{
|
|
37
|
+
name: "email",
|
|
38
|
+
label: t("auth.signup.email"),
|
|
39
|
+
placeholder: t("auth.signup.emailPlaceholder"),
|
|
40
|
+
type: "email",
|
|
41
|
+
autoComplete: "email",
|
|
42
|
+
autoFocus: true,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "password",
|
|
46
|
+
label: t("auth.signup.password"),
|
|
47
|
+
placeholder: t("auth.signup.passwordPlaceholder"),
|
|
48
|
+
type: "password",
|
|
49
|
+
autoComplete: "new-password",
|
|
50
|
+
},
|
|
51
|
+
]}
|
|
52
|
+
>
|
|
53
|
+
<LoginLink label={t("auth.signup.loginLink")} />
|
|
54
|
+
</AuthForm>
|
|
91
55
|
);
|
|
92
56
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { createContext } from
|
|
2
|
-
import { currentUserDetailsAtom } from
|
|
3
|
-
import type { AuthResponseDtoUserDetailDto } from
|
|
4
|
-
import { useAtomValue } from
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
import { currentUserDetailsAtom } from "@/modules/auth/hooks/use-auth-hook";
|
|
3
|
+
import type { AuthResponseDtoUserDetailDto } from "@/sdk";
|
|
4
|
+
import { useAtomValue } from "jotai";
|
|
5
5
|
|
|
6
|
-
export const AuthContext = createContext<
|
|
6
|
+
export const AuthContext = createContext<
|
|
7
|
+
AuthResponseDtoUserDetailDto | undefined
|
|
8
|
+
>(undefined);
|
|
7
9
|
|
|
8
10
|
export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
|
9
11
|
const authData = useAtomValue(currentUserDetailsAtom);
|
|
10
|
-
return
|
|
12
|
+
return (
|
|
13
|
+
<AuthContext.Provider value={authData}>{children}</AuthContext.Provider>
|
|
14
|
+
);
|
|
11
15
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Route as LoginRoute } from
|
|
1
|
+
import { Route as LoginRoute } from "@/routes/auth/login";
|
|
2
2
|
import type {
|
|
3
3
|
AuthResponseDtoUserDetailDto,
|
|
4
4
|
LoginUserAuthResponse,
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
ResetPasswordUserAuthResponse,
|
|
7
7
|
SendOtpUserAuthResponse,
|
|
8
8
|
ValidateTokenUserAuthResponse,
|
|
9
|
-
} from
|
|
9
|
+
} from "@/sdk";
|
|
10
10
|
import {
|
|
11
11
|
loginUserAuthMutation,
|
|
12
12
|
logoutUserAuthMutation,
|
|
@@ -14,31 +14,38 @@ import {
|
|
|
14
14
|
resetPasswordUserAuthMutation,
|
|
15
15
|
sendOtpUserAuthMutation,
|
|
16
16
|
validateTokenUserAuthMutation,
|
|
17
|
-
} from
|
|
18
|
-
import { client } from
|
|
19
|
-
import { useMutation } from
|
|
20
|
-
import { useNavigate } from
|
|
21
|
-
import { atom, useAtomValue, useSetAtom } from
|
|
22
|
-
import { atomWithStorage } from
|
|
23
|
-
import { useTranslation } from
|
|
24
|
-
import { toast } from
|
|
25
|
-
import { SupportedLanguages } from
|
|
26
|
-
import { DEFAULT_NON_LOGGED_IN_ROUTE } from
|
|
17
|
+
} from "@/sdk/@tanstack/react-query.gen";
|
|
18
|
+
import { client } from "@/sdk/client.gen";
|
|
19
|
+
import { useMutation } from "@tanstack/react-query";
|
|
20
|
+
import { useNavigate } from "@tanstack/react-router";
|
|
21
|
+
import { atom, useAtomValue, useSetAtom } from "jotai";
|
|
22
|
+
import { atomWithStorage } from "jotai/utils";
|
|
23
|
+
import { useTranslation } from "react-i18next";
|
|
24
|
+
import { toast } from "sonner";
|
|
25
|
+
import { SupportedLanguages } from "@/lib/i18n";
|
|
26
|
+
import { DEFAULT_NON_LOGGED_IN_ROUTE } from "@/lib/routes";
|
|
27
27
|
|
|
28
28
|
export const HEADER_KEYS = {
|
|
29
|
-
AUTH_TOKEN:
|
|
30
|
-
ACCEPT_LANGUAGE:
|
|
29
|
+
AUTH_TOKEN: "x-auth-token",
|
|
30
|
+
ACCEPT_LANGUAGE: "accept-language",
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
export const LOCAL_STORAGE_KEYS = {
|
|
34
|
-
AUTH_TOKEN:
|
|
34
|
+
AUTH_TOKEN: "authTokenAtom",
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
export const authTokenAtom = atomWithStorage<string>(
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
export const authTokenAtom = atomWithStorage<string>(
|
|
38
|
+
LOCAL_STORAGE_KEYS.AUTH_TOKEN,
|
|
39
|
+
"",
|
|
40
|
+
undefined,
|
|
41
|
+
{
|
|
42
|
+
getOnInit: true,
|
|
43
|
+
},
|
|
44
|
+
);
|
|
40
45
|
|
|
41
|
-
export const currentUserDetailsAtom = atom<
|
|
46
|
+
export const currentUserDetailsAtom = atom<
|
|
47
|
+
AuthResponseDtoUserDetailDto | undefined
|
|
48
|
+
>();
|
|
42
49
|
|
|
43
50
|
export const setTokenInClient = (token?: string | null) => {
|
|
44
51
|
if (token) {
|
|
@@ -72,13 +79,13 @@ export const useLogin = () => {
|
|
|
72
79
|
...loginUserAuthMutation({}),
|
|
73
80
|
onSuccess: (response: LoginUserAuthResponse) => {
|
|
74
81
|
const authData = response.data;
|
|
75
|
-
setAuthToken(authData?.token ||
|
|
82
|
+
setAuthToken(authData?.token || "");
|
|
76
83
|
setCurrentUser(authData);
|
|
77
84
|
setTokenInClient(authData?.token);
|
|
78
85
|
},
|
|
79
86
|
onError: (err) => {
|
|
80
|
-
console.error(
|
|
81
|
-
toast.error(err.response?.data.message || t(
|
|
87
|
+
console.error("Login error:", err);
|
|
88
|
+
toast.error(err.response?.data.message || t("auth.messages.loginFailed"));
|
|
82
89
|
},
|
|
83
90
|
});
|
|
84
91
|
};
|
|
@@ -91,13 +98,15 @@ export const useSignup = () => {
|
|
|
91
98
|
...registerUserAuthMutation({}),
|
|
92
99
|
onSuccess: (response: RegisterUserAuthResponse) => {
|
|
93
100
|
const authData = response.data;
|
|
94
|
-
setAuthToken(authData?.token ||
|
|
101
|
+
setAuthToken(authData?.token || "");
|
|
95
102
|
setCurrentUser(authData);
|
|
96
103
|
setTokenInClient(authData?.token);
|
|
97
104
|
},
|
|
98
105
|
onError: (err) => {
|
|
99
|
-
console.error(
|
|
100
|
-
toast.error(
|
|
106
|
+
console.error("Signup error:", err);
|
|
107
|
+
toast.error(
|
|
108
|
+
err.response?.data.message || t("auth.messages.signupFailed"),
|
|
109
|
+
);
|
|
101
110
|
},
|
|
102
111
|
});
|
|
103
112
|
};
|
|
@@ -113,13 +122,13 @@ export const useValidateToken = () => {
|
|
|
113
122
|
onSuccess: (response: ValidateTokenUserAuthResponse) => {
|
|
114
123
|
const authData = response.data;
|
|
115
124
|
setCurrentUser(authData);
|
|
116
|
-
setAuthToken(authData?.token ||
|
|
125
|
+
setAuthToken(authData?.token || "");
|
|
117
126
|
setTokenInClient(authData?.token);
|
|
118
127
|
},
|
|
119
128
|
onError: (err) => {
|
|
120
|
-
console.error(
|
|
129
|
+
console.error("Validate token error:", err);
|
|
121
130
|
setCurrentUser(undefined);
|
|
122
|
-
setAuthToken(
|
|
131
|
+
setAuthToken("");
|
|
123
132
|
setTokenInClient();
|
|
124
133
|
},
|
|
125
134
|
});
|
|
@@ -132,7 +141,7 @@ export const useLogout = () => {
|
|
|
132
141
|
return useMutation({
|
|
133
142
|
...logoutUserAuthMutation({}),
|
|
134
143
|
onSuccess: () => {
|
|
135
|
-
setAuthToken(
|
|
144
|
+
setAuthToken("");
|
|
136
145
|
setCurrentUser(undefined);
|
|
137
146
|
setTokenInClient();
|
|
138
147
|
navigate({ to: DEFAULT_NON_LOGGED_IN_ROUTE });
|
|
@@ -146,19 +155,21 @@ export const useSendOtp = () => {
|
|
|
146
155
|
return useMutation({
|
|
147
156
|
...sendOtpUserAuthMutation({}),
|
|
148
157
|
onSuccess: (response: SendOtpUserAuthResponse, variables) => {
|
|
149
|
-
toast.success(response.message || t(
|
|
158
|
+
toast.success(response.message || t("auth.messages.otpSentSuccess"));
|
|
150
159
|
// Extract email from the mutation variables and navigate to reset-password
|
|
151
160
|
const email = variables.query?.authId;
|
|
152
161
|
if (email) {
|
|
153
162
|
navigate({
|
|
154
|
-
to:
|
|
163
|
+
to: "/auth/reset-password",
|
|
155
164
|
search: { email },
|
|
156
165
|
});
|
|
157
166
|
}
|
|
158
167
|
},
|
|
159
168
|
onError: (err) => {
|
|
160
|
-
console.error(
|
|
161
|
-
toast.error(
|
|
169
|
+
console.error("Send OTP error:", err);
|
|
170
|
+
toast.error(
|
|
171
|
+
err.response?.data.message || t("auth.messages.otpSendFailed"),
|
|
172
|
+
);
|
|
162
173
|
},
|
|
163
174
|
});
|
|
164
175
|
};
|
|
@@ -169,12 +180,16 @@ export const useResetPassword = () => {
|
|
|
169
180
|
return useMutation({
|
|
170
181
|
...resetPasswordUserAuthMutation({}),
|
|
171
182
|
onSuccess: (response: ResetPasswordUserAuthResponse) => {
|
|
172
|
-
toast.success(
|
|
183
|
+
toast.success(
|
|
184
|
+
response.message || t("auth.messages.passwordResetSuccess"),
|
|
185
|
+
);
|
|
173
186
|
navigate({ to: LoginRoute.to });
|
|
174
187
|
},
|
|
175
188
|
onError: (err) => {
|
|
176
|
-
console.error(
|
|
177
|
-
toast.error(
|
|
189
|
+
console.error("Reset password error:", err);
|
|
190
|
+
toast.error(
|
|
191
|
+
err.response?.data.message || t("auth.messages.passwordResetFailed"),
|
|
192
|
+
);
|
|
178
193
|
},
|
|
179
194
|
});
|
|
180
195
|
};
|