NextJS Authentication with JWT

Viewed 160

I am new to NextJS (with TS) and I implemented it with redux (redux/toolkit). I also have separeted project for backend (auth is with JWT).

So what I want is to implement authentication in NextJS, where I would store token in cookie or localstorage, also put user data inside redux.

I will also have facebook/google auth.

My question is, how do I do this?

I tried to use next-auth, but I am not sure if it supports custom login page (I want to have login modal). Also, I want to register users that sign in thru fb/google on my backend. I am not sure if next-auth allows this, and how should I implement it?

Second approach is that I make everything custom. But here I am not sure where would I put the logic that gets the stored JWT, checks with backend, and store that to redux. I am thinking inside _app.tsx, but now I am not sure should that be done inside getServerSideProps (so nextjs backend checks with my backend) or componentDidMount (so I do that on the client side).

I looked up many examples, but most of them are with next-auth, but not with custom backend (that I have). They utilize backend of NextJS.

Any help would be greatly appreciated.

0 Answers
Related