Unable to exchange external code when login with Apple ID #40032
Unanswered
Sotatek-LongPham2
asked this question in
Questions
Replies: 1 comment
-
|
any updates? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Login form
`const handleAppleLogin = async () => {
setLoadingAppleLogin(true);
setErrorMessage(null);
try {
const { data, error } = await supabase.auth.signInWithOAuth({
provider: "apple",
options: {
redirectTo:
https://accusatival-suspectible-carmen.ngrok-free.dev/auth/callback,skipBrowserRedirect: true,
queryParams: {
scope: "name email",
},
},
});
console.log('data', data)
if (error) {
console.error("Login error:", error);
setLoadingAppleLogin(false);
}
} catch (err) {
console.error("Unexpected error:", err);
setLoadingAppleLogin(false);
}
};`
app/auth/callback/route.ts
`import { createClient } from '@/lib/supabase/server'
import { NextResponse } from 'next/server'
export async function GET(request: Request) {
const { searchParams } = new URL(request.url)
const code = searchParams.get('code')
console.log('code', code)
const next = searchParams.get('next') ?? '/'
const error = searchParams.get('error')
console.log('error', error)
const errorDescription = searchParams.get('error_description')
console.log('errorDescription', errorDescription)
// Handle OAuth errors
if (error) {
console.error('OAuth error:', error, errorDescription)
return NextResponse.redirect(
${process.env.NEXT_PUBLIC_SITE_URL}/auth/login?error=${encodeURIComponent(error)})
}
if (code) {
const supabase = await createClient()
}
// If no code or error occurred, redirect to login
return NextResponse.redirect(
${process.env.NEXT_PUBLIC_SITE_URL}/auth/login?error=no_code)}`
Beta Was this translation helpful? Give feedback.
All reactions