当前位置:网站首页>A login and exit component based on token
A login and exit component based on token
2022-04-23 20:28:00 【Yunmo - brother Kuang's blog】
note
1. Technical points related to login business
- http It's stateless
- adopt cookie Record the status on the client
- adopt session Record status on the server side
- adopt token The way to maintain state
Be careful :
- If there is no cross domain problem between our front-end and back-end interfaces , We usually use cookie and session To record the login status
- If there is a cross domain problem , We usually use token To maintain login status
2. token Principle analysis
token It is the only identity token to ensure that the user logs in successfully
- On the login page, enter the user name and password to log in
- After the server passes the authentication, the user's password is generated token value , And return the value to the client
Be careful :
- token Is generated by the server
- Each different user corresponds to token The values are different
- The client stores the token
- All subsequent requests from the client will carry this message token Send a request , So that our server can according to different token Value to determine which user the request belongs to , Return different results for different users
- The server verifies that token Whether there is , If it exists, it proves that you have logged in , And then according to this token To return the corresponding data
3. git Related knowledge
- Already installed git Configure public key if
- Instructions
- Check whether the current workspace is clean :git status
- Create a branch :git checkout -b “ Branch name ”
- View all branches :git branch ( hit * It's the current branch )
- Adds content from the working directory to the staging area :git add .
- Add the contents of the staging area to the local repository : git commit -m “ remarks ”
- Merge other branches :git merge “ Branch name to merge ”
4. Global style
- stay src Add a static directory under the directory assets/styles
- stay styles Create one in the directory css file
- stay main.js Import in
// Import global style sheet
import './assets/styles/reset.css'
// Import Font Icon
import './assets/fonts/iconfont.css'
5. The operation after login
- All of our pages should be accessed only after successful login , So how do we judge whether the login is successful , At this point, we need to use our token, because token After we successfully logged in , The only token issued to us by the server
- We need to perform the following two operations
- After successful login token, Save to client sessionStorage in
- There are other than login in the project API Interface , You must log in to access
- token Should only take effect while the current web site is open , So will token Save in sessionStorage in
window.sessionStorage.setItem("token", res.data.token);
- Jump to the background home page through programmed navigation , The routing address is /home
// First, configure the following in the routing table { path: '/home', component: Home } // And then in Login After successful login in the component, write a programmatic navigation object call push Method this.$router.push('/home')
6. Implementation of exit function
- principle :
-
be based on token It's easy to exit in the way of , Just destroy the local token that will do
-
such , Subsequent requests will not carry token, Must log in again to generate a new token Then you can visit the page
- The code is as follows :
// Empty token window.sessionStorage.clear() // Go to the landing page this.$router.push('/login')
版权声明
本文为[Yunmo - brother Kuang's blog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210551060974.html
边栏推荐
- 考研英语唐叔的语法课笔记
- Es index (document name) fuzzy query method (database name fuzzy query method)
- The construction and use of Fortress machine and springboard machine jumpserver are detailed in pictures and texts
- LeetCode 20、有效的括号
- Leetcode 994, rotten orange
- LeetCode 74、搜索二维矩阵
- go-zero框架数据库方面避坑指南
- Matlab analytic hierarchy process to quickly calculate the weight
- The flinkcdc reports an error: but this is no longer available on the server
- LeetCode 1337、矩阵中战斗力最弱的 K 行
猜你喜欢
WordPress plug-in: WP CHINA Yes solution to slow domestic access to the official website
After route link navigation, the sub page does not display the navigation style problem
Some basic knowledge of devexpress report development
[stack and queue topics] - sliding window
Error reported by Azkaban: Azkaban jobExecutor. utils. process. ProcessFailureException: Process exited with code 127
Plato Farm元宇宙IEO上线四大,链上交易颇高
考研英语唐叔的语法课笔记
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
LeetCode 116. 填充每个节点的下一个右侧节点指针
Actual measurement of automatic ticket grabbing script of barley network based on selenium (the first part of the new year)
随机推荐
Customize timeline component styles
黑客的入侵方式你知道几种?
R language uses timeroc package to calculate the multi time AUC value of survival data under competitive risk, uses Cox model and adds covariates, and R language uses the plotauccurve function of time
Browser - learning notes
BMP JPEG 图片转换为矢量图像 ContourTrace
How can matlab obtain the truncated image in trainingimagelabeler
Cadence OrCAD capture batch change component packaging function introduction graphic tutorial and video demonstration
Mysql database backup scheme
BMP JPEG picture to vector image contourtrace
Zdns was invited to attend the annual conference of Tencent cloud basic resources and share the 2020 domain name industry development report
JDBC database addition, deletion, query and modification tool class
Scripy tutorial - (2) write a simple crawler
Devaxpress report replay: complete the drawing of conventional two-dimensional report + histogram + pie chart
Parsing methods of JSON data in C - jar and jobobject: error reading jar from jsonreader Current JsonReader item
selenium. common. exceptions. WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
Three. Based on ply format point cloud voxel model JS upload interface writing
Solve the Chinese garbled code of URL in JS - decoding
JDBC tool class jdbcconutil gets the connection to the database
SQL Server Connectors By Thread Pool | DTSQLServerTP 插件使用说明
A useless confession artifact