#216 done by using return-to URL mechanism
This commit is contained in:
@@ -14,6 +14,8 @@ export default defineStore('loginStore', {
|
||||
},
|
||||
isInvalid: false,
|
||||
userData: {},
|
||||
isLoggedIn: false,
|
||||
rememberedReturnToUrl: "",
|
||||
// expired: new Date().setMonth(6), // 設定 Refresh Token 的到期日為半年後
|
||||
}),
|
||||
actions: {
|
||||
@@ -38,7 +40,18 @@ export default defineStore('loginStore', {
|
||||
document.cookie = `luciaToken=${accessToken}`;
|
||||
// document.cookie = `luciaRefreshToken=${refreshToken};expires=${new Date(this.expired)};`;
|
||||
|
||||
this.$router.push('/files');
|
||||
this.isLoggedIn = true;
|
||||
|
||||
// 大部分的情況下,預設導向至 FILES 頁面
|
||||
// 然而有一種情況是使用者在沒有登入的情況下貼上了某一個頁面的網址,
|
||||
// 則在此情況下時,我們會在使用者稍後登入後,把使用者帶到剛才記住的 return-to 網址
|
||||
if(this.rememberedReturnToUrl !== "") {
|
||||
console.log('1111', );
|
||||
window.location.href = this.rememberedReturnToUrl;
|
||||
} else {
|
||||
console.log('2222', );
|
||||
this.$router.push('/login');
|
||||
}
|
||||
} catch(error) {
|
||||
this.isInvalid = true;
|
||||
};
|
||||
@@ -72,6 +85,9 @@ export default defineStore('loginStore', {
|
||||
logOut() {
|
||||
delete axios.defaults.headers.common["Authorization"];
|
||||
document.cookie = 'luciaToken=; expires=Thu, 01 Jan 1970 00:00:00 UTC;';
|
||||
|
||||
this.isLoggedIn = false;
|
||||
|
||||
this.$router.push('/login');
|
||||
},
|
||||
/**
|
||||
@@ -100,5 +116,8 @@ export default defineStore('loginStore', {
|
||||
this.$router.push('/login');
|
||||
};
|
||||
},
|
||||
setRememberedReturnToUrl(returnToUrl){
|
||||
this.rememberedReturnToUrl = returnToUrl
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user