For a small app catering to a very small set of users, we are planning to implement magic link authentication. The user would come to the application, enter their email address, get a magic link on the email address, after the user clicks on the link, they are logged in to the app.
I am not able to find enough resources to figure out how to do it in a SPA. Here are some helpful links:
Magic Link with Node
- https://medium.com/@aleksandrasays/sending-magic-links-with-nodejs-765a8686996
- https://medium.com/one-more-thing-studio/how-to-make-magic-links-with-node-1d164c036e29
Magic Link with Auth0
This is the SPA workflow that I have in mind:
- User comes to the SPA
- The SPA takes the user to the login page where they can provide their email address.
- The SPA sends the email address to the backend api
- The api decides whether or not the user is registered, and sends them an email with a short lived jwt.
- Clicking on this link takes user to a SPA route with the jwt in query params.
- The Frontend forwards this jwt to the api backend, and the api backend verifies the jwt and sets a cookie
- This cookie can then be used to maintain the user session.
I want to verify this workflow, but I am not able to find enough resources. Specifically, I want to clarify whether the magic link should send the user to the SPA and the SPA should be responsible for extracting the jwt and sending it to the API backend, or is there another way to do it?
Is this how this should be implemented? What are the security implications?
I am using react and react-router.