refactor(auth): use vueuse's useLocalStorage (#142)
* refactor(auth): replace native localStorage API with vueuse's useLocalStorage API
* chore(auth): Add explicit import for useLocalStorage
* chore(auth): Set token to null
---------
Co-authored-by: Charlie ✨ <18888351756@163.com>
This commit is contained in:
parent
874835e32b
commit
e575881c28
|
|
@ -1,19 +1,22 @@
|
|||
import { STORAGE_TOKEN_KEY } from '@/stores/mutation-type'
|
||||
import { useLocalStorage } from '@vueuse/core'
|
||||
|
||||
const token = useLocalStorage(STORAGE_TOKEN_KEY, '')
|
||||
|
||||
function isLogin() {
|
||||
return !!localStorage.getItem(STORAGE_TOKEN_KEY)
|
||||
return !!token.value
|
||||
}
|
||||
|
||||
function getToken() {
|
||||
return localStorage.getItem(STORAGE_TOKEN_KEY)
|
||||
return token.value
|
||||
}
|
||||
|
||||
function setToken(token: string) {
|
||||
localStorage.setItem(STORAGE_TOKEN_KEY, token)
|
||||
function setToken(newToken: string) {
|
||||
token.value = newToken
|
||||
}
|
||||
|
||||
function clearToken() {
|
||||
localStorage.removeItem(STORAGE_TOKEN_KEY)
|
||||
token.value = null
|
||||
}
|
||||
|
||||
export { isLogin, getToken, setToken, clearToken }
|
||||
|
|
|
|||
Loading…
Reference in New Issue