I was wondering what the preferred method is for persisting a user to a separate API Django backend upon successful signup/login on my Next SPA. Note that I have also opted to use the React Auth0 SDK because I am intending to deploy as a static site. I have looked into the following methods (each with their shortcomings) and am not sure if I’ve covered all my bases.
- Use an Auth0 Rule: A custom rule to hit and endpoint on my server after user creation. This doesn’t seem like it would work for localhost development and would have to change Ngrok destinations for every developer working on the app.
- Redirect to another page: Utilizing the onRedirectCallback in the Auth0Provider and redirecting to a dummy component that could access the getAccessTokenSilently hook to request an endpoint on the server. This would have to deal with visual blips to the end user.
- Request endpoint directly in the onRedirectCallback: This lives outside of the Auth0Provider and doesn’t seem to be able to directly access the auth token. Alternately, I tried creating a Next.js API endpoint, but getAccessTokenSilently doesn’t work with function handlers.
I have also seen this Gist that creates an AxiosProvider, but only seems to be helpful for #2 above. I think I’ve focused on the onRedirectCallback event as it seems like that’s the only definitive lifecycle event that fires after successful login. Any help or any ideas to further investigate would be greatly appreciated.