Next.js Discord

Discord Forum

NextJS auth with spring backend

Unanswered
Siamese Crocodile posted this in #help-forum
Open in Discord
Avatar
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

2 Replies

Avatar
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
Avatar
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 details
You just create an endpoints such as GET /users/me, that checks reads the user identity from a cookie and return the profile of this user

implement restricted routes feature based on user’s authZ and authN status
The logic lives on the backend side, while frontend just handles the responses from the backend