DEV Community

loading...

Discussion on: How to add authentication to your universal Nuxt app using nuxt/auth module?

Collapse
richardcullen profile image
RichardCullen

Need to include some sample code to show how to implement the server-side of the Auth API.

Collapse
zloypacifist profile image
zloypacifist

I've made 2 api endpoints on my server localhost:8080 for login and profile.
On login endpoint: if user credentials is valid, set cookie 'myauth' with some unique value (token), and save this token for user in DB.
On profile endpoint: if cookie 'myauth' set and user found by token, return json with it's profile info, for example:
{
"id: 1,
"name": "Jon Snow",
"email": "jon.snow@asoiaf.com"
}
else return 401 status code with empty response.

After this manipulating my nuxt app start to login users. I've used auth middleware in nuxt config for all routings. I've used Lumen framework for api server