OAuth with PKCE flow for SSR
Learn how to configure OAuth authentication in your server-side rendering (SSR) application to work with the PKCE flow.
Setting up SSR client
Check out our guide for creating a client to learn how to install the necessary packages, declare environment variables, and create a Supabase client configured for SSR in your framework.
Create API endpoint for handling the code
exchange
In order to use OAuth we will need to setup a endpoint for the code
exchange, to exchange an auth code
for the user's session
, which is set as a cookie for future requests made to Supabase.
Create a new file at app/auth/callback/route.ts
and populate with the following:
Let's point our .signInWithOAuth
method's redirect to the callback route we create above:
_10await supabase.auth.signInWithOAuth({_10 provider,_10 options: {_10 redirectTo: `http://example.com/auth/callback`,_10 },_10})