Code Monkey home page Code Monkey logo

Comments (7)

aiden0w0 avatar aiden0w0 commented on May 20, 2024 2

get~谢谢大佬w

from vue-example-login.

doterlin avatar doterlin commented on May 20, 2024 1

我说的token只是打个比方,简单的登录的话就是后端验证账号密码没问题后,就给客户端设置一个cookie就行了(这个cookie就是token)。客户端来判断是否存在这个cookie就ok,在登录后调用api都要带上这个token和user_id等,否则别人手动加了个cookie就可以免登录调到用户信息了。
token的生成是由已有的信息,比如用户的id,登录账号等经过加密处理(如md5( uid + 暗号 ))得到的,一般还要设置有效期扔到Redis这类缓存,所以不需要另建表。

from vue-example-login.

doterlin avatar doterlin commented on May 20, 2024

不太明白你说的意思哦。

from vue-example-login.

aiden0w0 avatar aiden0w0 commented on May 20, 2024

本来是想问如果我有多个页面,怎么能checkLogin(demo里是没cookie跳login有cookie跳info)。现在用的笨办法是每个页面判断没cookie跳login。不知道有没有更好的解决方法~

from vue-example-login.

aiden0w0 avatar aiden0w0 commented on May 20, 2024

另一个问题是,cookie里面设置的token是怎么获取的呢...之前用php的话session是后端自己处理完毕。
想到的流程是

  1. 前端验证登录
  2. api验证登录 信息正确的话生成一串token放在数据库中并返回给前端
    但是这样的话每个页面验证都要读一次数据库 感觉不太对

from vue-example-login.

doterlin avatar doterlin commented on May 20, 2024

@fisherwise 一个域名下的所有页面的cookie是共享的,多个页面也没关系吧。
另外,像token这些是后端进行对session做了处理后,返回给客户端,客户端用cookie保存起来。用户打开页面时如果该cookie存在就免登陆不需要每次都到数据库,否则才去请求后端。

from vue-example-login.

aiden0w0 avatar aiden0w0 commented on May 20, 2024

就是说后端api自己维护一个表?

from vue-example-login.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.