[NextAuth]: How to programmatically login user on the back-end?

Viewed 394

I use several providers, including credentials provider (email & password) At some point, in the app, user can ask for 'restore password' email where he should get one-time link. After he visits the link (/api/users/quick_link?token=XXX&email) I check if the token is valid and after that my goal is to login user and to redirect him to his profile page.

What have I tried:

  1. Using 'nextauth/client' signIn function, which obviously does not work on back-end
  2. Checking how they do 'email' provider - the starting part is more or less the same, but it quickly start using internal functions, which I do not plan (at least now) to touch.

What I have not tried: Using REST API.

Because I am not sure how to use it from another api. Just await fetch?

Recap

Short version: after visiting /api/users/login_me_asap?myemail=xxx I want to login user and redirect him.

0 Answers
Related