Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Token based Authentication with Ream #35

Open
ansarizafar opened this issue Apr 21, 2017 · 9 comments
Open

Token based Authentication with Ream #35

ansarizafar opened this issue Apr 21, 2017 · 9 comments

Comments

@ansarizafar
Copy link

How token based authentication can be implemented with Ream. Is there any example available?

@egoist
Copy link
Collaborator

egoist commented Apr 21, 2017

I guess you mean custom server? If you're using express you can use express-jwt, no example for now.

@ansarizafar
Copy link
Author

ansarizafar commented Apr 21, 2017

I am using express-jwt and express session to store token in a cookie. How can I set axios header, authorize routes and access token in vue components. Nuxt uses middle ware to set axios header like this

import axios from 'axios'

export default function({isServer, req}) {
  if (isServer) {
    axios.defaults.headers.common.cookie = req.headers.cookie
  }
}

and then store token in store

nuxtServerInit ({ commit }, { req }) {
  if (req.session && req.session.authUser) {
    commit('SET_USER', req.session.authUser)
  }
}

@ansarizafar
Copy link
Author

@egoist An authentication/route authorization example with express-jwt and custom expressjs server would be very useful for developers new to Ream.

@cannap
Copy link

cannap commented Apr 22, 2017

@ansarizafar
you can do this like in all other vuejs apps with or without ream

you cann follow this: https://github.com/auth0-blog/vue-jwt-authentication this will give you the idea but dont forget to use bcrypt to save the password on serverside they dont show this part

@jazoom
Copy link

jazoom commented Apr 23, 2017

I've already explained that to him, but he keeps asking: ream/ream#23 (comment)

I'm guessing he hasn't gone through any tutorials yet.

@ansarizafar
Copy link
Author

I am using Token based authentication in my projects from last 3 years. @cannap the tutorial you mentioned is about client side. If routes/pages are rendered on the server then you can't get token from localstorage as there is no localstorage available on the server. See how it can be done with Nuxt https://nuxtjs.org/examples/auth-routes

@jazoom
Copy link

jazoom commented Apr 23, 2017

Since you've been doing it for 3 years, how do you normally get the token to the server? Just add it to a header, or to the body, or in the query string when you make the request.

@ansarizafar
Copy link
Author

@egoist Could you please suggest a solution, especially for those who don't understand how SSR works.

@egoist
Copy link
Collaborator

egoist commented May 29, 2018

I added a simple auth example: https://github.com/ream/ream/tree/master/examples/with-auth

This does not include an API implementation but only a client workflow.

Basically you only need to check if it's a valid user in entry file's middleware method or component's getInitialData method:

https://github.com/ream/ream/blob/76b13d34aa9b0dd6da35df62dd990639f32b66a8/examples/with-auth/index.js#L28-L44

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants