Issues Using Linked Singin option with supabase OAuth #22711
Unanswered
Daniel-Alamezie
asked this question in
Questions
Replies: 1 comment 6 replies
-
https://github.com/orgs/supabase/discussions/22708 |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am setting up a project that uses linkedIn signin options with supabase when i enter the user email and password it redirects me to my homepage with this message.
Anyone have ideas why this could be ?
?error=server_error&error_code=500&error_description=Error+getting+user+profile+from+external+provider#error=server_error&error_code=500&error_description=Error+getting+user+profile+from+external+provider.
for context this is what my client and server code looks like.
Client code
export default function LoginPage() {
useEffect(() => {
if (window.location.search.includes('error')) {
console.error('Error during the OAuth flow');
}
}, []);
async function signInWithLinkedIn() {
const supabase = supabaseBrowser();
const { error } = await supabase.auth.signInWithOAuth({
provider: 'linkedin_oidc',
options: {
redirectTo:
${window.location.origin}/auth/callback
,}
});
if (error) {
console.error('Error signing in:', error);
}
}
return (
Login with LinkedIn
)
server code
import { cookies } from 'next/headers'
import { NextResponse } from 'next/server'
import { type CookieOptions, createServerClient } from '@supabase/ssr'
export async function GET(request: Request) {
const { searchParams, origin } = new URL(request.url)
const code = searchParams.get('code')
// if "next" is in param, use it as the redirect URL
const next = searchParams.get('next') ?? '/'
if (code) {
const cookieStore = cookies()
const supabase = createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
get(name: string) {
return cookieStore.get(name)?.value
},
set(name: string, value: string, options: CookieOptions) {
cookieStore.set({ name, value, ...options })
},
remove(name: string, options: CookieOptions) {
cookieStore.delete({ name, ...options })
},
},
}
)
const { error } = await supabase.auth.exchangeCodeForSession(code)
if (!error) {
return NextResponse.redirect(
${origin}/
)}
}
// return the user to an error page with instructions
return NextResponse.redirect(
${origin}/auth/auth-code-error
)}
Beta Was this translation helpful? Give feedback.
All reactions