Skip to content

Commit

Permalink
fix: judge isLoaded first
Browse files Browse the repository at this point in the history
  • Loading branch information
jsun969 committed Jan 17, 2024
1 parent fe9194b commit deb3adf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
15 changes: 7 additions & 8 deletions src/app/(account)/forgot-password/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const STEP_INSTRUCTIONS = [

export default function ForgotPasswordPage() {
const [step, setStep] = useState(1);
const { signIn, setActive } = useSignIn();
const { isLoaded, signIn, setActive } = useSignIn();

const sendCodeForm = useForm<z.infer<typeof sendCodeSchema>>({
defaultValues: { email: '' },
Expand All @@ -46,8 +46,9 @@ export default function ForgotPasswordPage() {
});

const handleSendCode = sendCodeForm.handleSubmit(async ({ email }) => {
if (!isLoaded) return;
try {
const result = await signIn?.create({
const result = await signIn.create({
strategy: 'reset_password_email_code',
identifier: email,
});
Expand All @@ -72,17 +73,15 @@ export default function ForgotPasswordPage() {
});

const handleResetPassword = resetPasswordForm.handleSubmit(async ({ code, password }) => {
if (!isLoaded) return;
try {
const resetResult = await signIn?.attemptFirstFactor({
const resetResult = await signIn.attemptFirstFactor({
strategy: 'reset_password_email_code',
code,
password,
});

if (resetResult?.status === 'complete') {
if (setActive) {
setActive({ session: resetResult.createdSessionId });
}
if (resetResult.status === 'complete') {
setActive({ session: resetResult.createdSessionId });
setStep(3);
}
} catch (error) {
Expand Down
13 changes: 6 additions & 7 deletions src/app/(account)/sign-in/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,13 @@ export default function SignInForm() {
});

const handleGoogleSignIn = async () => {
if (!isLoaded) return;
try {
if (signIn) {
await signIn.authenticateWithRedirect({
strategy: 'oauth_google',
redirectUrl: '/sso-callback',
redirectUrlComplete: '/',
});
}
await signIn.authenticateWithRedirect({
strategy: 'oauth_google',
redirectUrl: '/sso-callback',
redirectUrlComplete: '/',
});
} catch (error) {
// Handle any errors that might occur during the sign-in process
console.error('Google Sign-In Error:', error);
Expand Down

0 comments on commit deb3adf

Please sign in to comment.