NextJS auth with spring backend
Unanswered
Siamese Crocodile posted this in #help-forum
Siamese CrocodileOP
I found this implementation that allows NextJS front end to work with a spring boot backend in a auth context. The backend spring has session cookie based auth setup and I want my NextJS front end to simply act as a frontend only. Is this a good implementation? Could there be better alternatives?
https://github.com/NerminKarapandzic/spring-boot-nextjs-starter-kit/blob/master/frontend/lib/auth/use-auth.ts
https://github.com/NerminKarapandzic/spring-boot-nextjs-starter-kit/blob/master/frontend/lib/auth/use-auth.ts
2 Replies
Siamese CrocodileOP
I basically want to be able to access logged in user’s details on the frontend and also implement restricted routes feature based on user’s authZ and authN status
Harrier
I think this heavily relies on the API you expose from your spring backend. The backend is responsible for authn and authz, while frontend is just a presentation layer in this case.
want to be able to access logged in user’s detailsYou just create an endpoints such as
GET /users/me
, that checks reads the user identity from a cookie and return the profile of this userimplement restricted routes feature based on user’s authZ and authN statusThe logic lives on the backend side, while frontend just handles the responses from the backend