Skip to content

Commit 54e716b

Browse files
committed
Error handling for Apple login too
1 parent f4e9f8f commit 54e716b

File tree

1 file changed

+11
-5
lines changed
  • src/app/(landing)/oauth-callback/apple

1 file changed

+11
-5
lines changed

src/app/(landing)/oauth-callback/apple/page.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client"
22

33
import { Suspense, useEffect, useState } from "react"
4-
import { useSearchParams } from "next/navigation"
4+
import { useRouter, useSearchParams } from "next/navigation"
55
import { useAuth } from "@/providers/auth-provider"
66
import { useTurnkey } from "@turnkey/sdk-react"
77
import { Loader } from "lucide-react"
@@ -14,6 +14,7 @@ function OAuthProcessCallback() {
1414

1515
const { authIframeClient } = useTurnkey()
1616
const { loginWithApple } = useAuth()
17+
const router = useRouter()
1718

1819
const [storedToken, setStoredToken] = useState<string | null>(null) // Store the token locally
1920
const [hasLoggedIn, setHasLoggedIn] = useState(false) // Track if loginWithOAuth has been called
@@ -33,11 +34,16 @@ function OAuthProcessCallback() {
3334
// Trigger loginWithOAuth when both token and iframePublicKey are available, but only once
3435
useEffect(() => {
3536
if (storedToken && authIframeClient?.iframePublicKey && !hasLoggedIn) {
36-
// Call the OAuth login function with the stored token
37-
loginWithApple(storedToken)
37+
try {
38+
// Call the OAuth login function with the stored token
39+
loginWithApple(storedToken)
3840

39-
// Set flag to prevent further calls
40-
setHasLoggedIn(true)
41+
// Set flag to prevent further calls
42+
setHasLoggedIn(true)
43+
} catch (error) {
44+
const msg = "Error logging in with Apple: " + error
45+
router.push(`/?error=${encodeURIComponent(msg)}`)
46+
}
4147
}
4248
}, [
4349
storedToken,

0 commit comments

Comments
 (0)