I am trying to implement several Supabase authentication flows using Netlify edge functions (as to not leak Supabase client keys in the browser.) Some of these flows, including signIn with magic link and resetting password, include sending an email to a user which they open, and it contains some data related to the session in the URL – which is then used with the authentication flow (e.g. verify sign in using magic link, or permission to reset password for user.)
I asked about this in a Supabase help forum, and they said the following:
You normally have to redirect to a browser page to for the url link to be processed.
I don’t do server side stuff and not sure in a netlify function exactly what is going to happen. On a server you have to have persistSession:false in your createClient as there is not local storage. I am also skeptical you will get the session tokens as they are behind a fragment in the redirect URL and it won’t see them on a server.
… You probably need to look into a framework that supports sever side pages and then use auth-helpers which uses cookies to communicate among all the various clients. It handles the redirects with pkce which does work on the server. It is not directly related to edge type functions (I assume a netlify function is that, but not sure). Normally for a separate server type function you have to set the Authorization header and then read the header in the function to get the user jwt. But you already have to be signed in to have that jwt.
Can anybody recommend a way to do configure a netlify deployment, so that when a user clicks a link in their email to sign in via magic link or reset their password, it will work as expected? I am doing this in nodeJS but mainly just HTML, vanilla JS, and htmx for the software stack.