Skip to content

Commit 7be8c00

Browse files
committed
cleanup login
1 parent 224898f commit 7be8c00

File tree

6 files changed

+153
-175
lines changed

6 files changed

+153
-175
lines changed

apps/dashboard/app/(auth)/login/forgot/page.tsx

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,22 @@ export default function ForgotPasswordPage() {
2020
return;
2121
}
2222
setIsLoading(true);
23-
try {
24-
await authClient.forgetPassword({
25-
email,
26-
fetchOptions: {
27-
onSuccess: () => {
28-
setIsLoading(false);
29-
toast.success('Password reset instructions sent to your email.');
30-
},
31-
onError: () => {
32-
setIsLoading(false);
33-
toast.error('Failed to send reset instructions. Please try again.');
34-
},
23+
24+
await authClient.forgetPassword({
25+
email,
26+
fetchOptions: {
27+
onSuccess: () => {
28+
setIsLoading(false);
29+
toast.success('Password reset instructions sent to your email.');
3530
},
36-
});
37-
} catch (_error) {
38-
setIsLoading(false);
39-
toast.error('An error occurred. Please try again later.');
40-
}
31+
onError: () => {
32+
setIsLoading(false);
33+
toast.error('Failed to send reset instructions. Please try again.');
34+
},
35+
},
36+
});
37+
38+
setIsLoading(false);
4139
};
4240

4341
return (

apps/dashboard/app/(auth)/login/magic-sent/page.tsx

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,23 @@ export default function MagicSentPage() {
2020
return;
2121
}
2222
setIsLoading(true);
23-
try {
24-
await signIn.magicLink({
25-
email,
26-
callbackURL: '/home',
27-
fetchOptions: {
28-
onSuccess: () => {
29-
setIsLoading(false);
30-
toast.success('Magic link sent! Please check your email.');
31-
},
32-
onError: () => {
33-
setIsLoading(false);
34-
toast.error('Failed to send magic link. Please try again.');
35-
},
23+
24+
await signIn.magicLink({
25+
email,
26+
callbackURL: '/home',
27+
fetchOptions: {
28+
onSuccess: () => {
29+
setIsLoading(false);
30+
toast.success('Magic link sent! Please check your email.');
3631
},
37-
});
38-
} catch (_error) {
39-
setIsLoading(false);
40-
toast.error('Failed to send magic link. Please try again.');
41-
}
32+
onError: () => {
33+
setIsLoading(false);
34+
toast.error('Failed to send magic link. Please try again.');
35+
},
36+
},
37+
});
38+
39+
setIsLoading(false);
4240
};
4341

4442
return (

apps/dashboard/app/(auth)/login/magic/page.tsx

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,24 @@ export default function MagicLinkPage() {
2222
return;
2323
}
2424
setIsLoading(true);
25-
try {
26-
await signIn.magicLink({
27-
email,
28-
callbackURL: '/home',
29-
fetchOptions: {
30-
onSuccess: () => {
31-
setIsLoading(false);
32-
toast.success('Magic link sent! Please check your email.');
33-
router.push(`/login/magic-sent?email=${encodeURIComponent(email)}`);
34-
},
35-
onError: () => {
36-
setIsLoading(false);
37-
toast.error('Failed to send magic link. Please try again.');
38-
},
25+
26+
await signIn.magicLink({
27+
email,
28+
callbackURL: '/home',
29+
fetchOptions: {
30+
onSuccess: () => {
31+
setIsLoading(false);
32+
toast.success('Magic link sent! Please check your email.');
33+
router.push(`/login/magic-sent?email=${encodeURIComponent(email)}`);
3934
},
40-
});
41-
} catch (_error) {
42-
setIsLoading(false);
43-
toast.error('Failed to send magic link. Please try again.');
44-
}
35+
onError: () => {
36+
setIsLoading(false);
37+
toast.error('Failed to send magic link. Please try again.');
38+
},
39+
},
40+
});
41+
42+
setIsLoading(false);
4543
};
4644

4745
return (

apps/dashboard/app/(auth)/login/page.tsx

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import { signIn } from '@databuddy/auth/client';
4-
import { Eye, EyeOff, Github, Loader2, Mail, Sparkles } from 'lucide-react';
4+
import { Eye, EyeOff, GithubIcon, Loader2, Mail, Sparkles } from 'lucide-react';
55
import Link from 'next/link';
66
import { useRouter } from 'next/navigation';
77
import { Suspense, useEffect, useState } from 'react';
@@ -67,38 +67,35 @@ function LoginPage() {
6767
}
6868

6969
setIsLoading(true);
70-
try {
71-
await signIn.email({
72-
email,
73-
password,
74-
callbackURL: '/websites',
75-
fetchOptions: {
76-
onSuccess: () => {
77-
localStorage.setItem('lastUsedLogin', 'email');
78-
},
79-
onError: (error) => {
80-
setIsLoading(false);
81-
if (
82-
error?.error?.code === 'EMAIL_NOT_VERIFIED' ||
83-
error?.error?.message?.toLowerCase().includes('not verified')
84-
) {
85-
router.push(
86-
`/login/verification-needed?email=${encodeURIComponent(email)}`
87-
);
88-
} else {
89-
toast.error(
90-
error?.error?.message ||
91-
'Login failed. Please check your credentials and try again.'
92-
);
93-
}
94-
},
70+
71+
await signIn.email({
72+
email,
73+
password,
74+
callbackURL: '/websites',
75+
fetchOptions: {
76+
onSuccess: () => {
77+
localStorage.setItem('lastUsedLogin', 'email');
9578
},
96-
});
97-
} catch (_error) {
98-
toast.error('Something went wrong');
99-
} finally {
100-
setIsLoading(false);
101-
}
79+
onError: (error) => {
80+
setIsLoading(false);
81+
if (
82+
error?.error?.code === 'EMAIL_NOT_VERIFIED' ||
83+
error?.error?.message?.toLowerCase().includes('not verified')
84+
) {
85+
router.push(
86+
`/login/verification-needed?email=${encodeURIComponent(email)}`
87+
);
88+
} else {
89+
toast.error(
90+
error?.error?.message ||
91+
'Login failed. Please check your credentials and try again.'
92+
);
93+
}
94+
},
95+
},
96+
});
97+
98+
setIsLoading(false);
10299
};
103100

104101
return (
@@ -122,7 +119,7 @@ function LoginPage() {
122119
type="button"
123120
variant="outline"
124121
>
125-
<Github className="mr-2 h-5 w-5" />
122+
<GithubIcon className="mr-2 h-5 w-5" />
126123
<span className="flex items-center gap-2">
127124
Sign in with GitHub
128125
{lastUsed === 'github' && (

apps/dashboard/app/(auth)/login/verification-needed/page.tsx

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,25 @@ export default function VerificationNeededPage() {
1515

1616
const sendVerificationEmail = async () => {
1717
setIsLoading(true);
18-
try {
19-
await authClient.sendVerificationEmail({
20-
email,
21-
callbackURL: '/home',
22-
fetchOptions: {
23-
onSuccess: () => {
24-
toast.success('Verification email sent!');
25-
setIsLoading(false);
26-
},
27-
onError: () => {
28-
setIsLoading(false);
29-
toast.error(
30-
'Failed to send verification email. Please try again later.'
31-
);
32-
},
18+
19+
await authClient.sendVerificationEmail({
20+
email,
21+
callbackURL: '/home',
22+
fetchOptions: {
23+
onSuccess: () => {
24+
toast.success('Verification email sent!');
25+
setIsLoading(false);
26+
},
27+
onError: () => {
28+
setIsLoading(false);
29+
toast.error(
30+
'Failed to send verification email. Please try again later.'
31+
);
3332
},
34-
});
35-
} catch (_error) {
36-
setIsLoading(false);
37-
toast.error('Failed to send verification email. Please try again later.');
38-
}
33+
},
34+
});
35+
36+
setIsLoading(false);
3937
};
4038

4139
return (

0 commit comments

Comments
 (0)