Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我的学习日志(七) #8

Open
3 tasks done
xxxgitone opened this issue Jun 9, 2017 · 0 comments
Open
3 tasks done

我的学习日志(七) #8

xxxgitone opened this issue Jun 9, 2017 · 0 comments

Comments

@xxxgitone
Copy link
Owner

xxxgitone commented Jun 9, 2017

继续常规学习,充实,哈哈 💥

任务

知识点

在使用token做登录验证的时候,将后来发送过来的token保存在cookie、sessionStorage或者localStorage中,想要获取用户信息的时候,先拿到token,载发送给后端,进行解析token,查找用户,返回用户信息即可

可以有多种方式向后端发送token(前端axios发送请求,后端node接收并验证)

  • 将token放在请求头信息中
    前端:axios.get('/auth/user', {headers: {token: token}})
    后端:req.headers.toke
  • 将token作为路径的查询参数(http://localhost:8080/auth/user?token=)
    前端: axios.get('/auth/user', {params: {token: token}})
    后端: req.params.token
  • 如果是表单,可以将token放在表单中一个隐藏文本框,然后跟随表单信息一同发至后台
    后端: req.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant