Skip to content

OAuth sign in isn't redirecting on the server side

这个限制的原因是 auth helpers 库缺少一个直接执行服务器端重定向的机制,因为每个框架处理重定向的方式都不一样。不过,该库确实通过它返回的数据属性提供了一个 URL,可以用来进行重定向。

🌐 The reason behind this limitation is that the auth helpers library lacks a direct mechanism for performing server-side redirects, as each framework handles redirects differently. However, the library does offer a URL through the data property it returns, which should be used for the purpose of redirection.

Next.js:

1
import { NextResponse } from "next/server";
2
...
3
const { data } = await supabase.auth.signInWithOAuth({
4
provider: 'github',
5
})
6
7
return NextResponse.redirect(data.url)

SvelteKit:

1
import { redirect } from '@sveltejs/kit';
2
...
3
const { data } = await supabase.auth.signInWithOAuth({
4
provider: 'github',
5
})
6
7
throw redirect(303, data.url)

混音:

1
import { redirect } from "@remix-run/node"; // or cloudflare/deno
2
...
3
const { data } = await supabase.auth.signInWithOAuth({
4
provider: 'github',
5
})
6
7
return redirect(data.url)