Skip to content

Commit 4a88ca5

Browse files
author
feige996
committed
refactor(登录): 调整登录流程中token和用户信息的设置顺序
将token设置移到用户信息设置之前,以更符合常见登录流程
1 parent 68d1431 commit 4a88ca5

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/pages/login/login.vue

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ async function doLogin() {
3232
return
3333
}
3434
try {
35-
// 1/2 调用接口回来后设置用户信息
35+
// 有的时候后端会用一个接口返回token和用户信息,有的时候会分开2个接口(各有利弊,看业务场景和系统复杂度),这里使用2个接口返回的来模拟
36+
// 1/2 调用接口回来后设置token信息
37+
// 这里用单token来模拟
38+
tokenStore.setTokenInfo({
39+
token: '123456',
40+
expiresIn: 60 * 60 * 24 * 7,
41+
})
42+
43+
// 2/2 调用接口回来后设置用户信息
3644
// const res = await login({
3745
// username: '菲鸽',
3846
// password: '123456',
@@ -44,12 +52,7 @@ async function doLogin() {
4452
nickname: '菲鸽',
4553
avatar: 'https://oss.laf.run/ukw0y1-site/avatar.jpg',
4654
})
47-
// 2/2 调用接口回来后设置token信息
48-
// 这里用单token来模拟
49-
tokenStore.setTokenInfo({
50-
token: '123456',
51-
expiresIn: 60 * 60 * 24 * 7,
52-
})
55+
5356
console.log(redirectUrl.value)
5457
}
5558
catch (error) {

0 commit comments

Comments
 (0)