1
This commit is contained in:
35
src/popup/hook/use-login.ts
Normal file
35
src/popup/hook/use-login.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import {computed, onMounted, ref} from "vue";
|
||||
import {getToken, logout, setToken} from "@/shared/auth";
|
||||
|
||||
export const useLogin = () => {
|
||||
const token = ref<string | null>(null);
|
||||
|
||||
const isLoggedIn = computed(() => token.value !== null);
|
||||
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
const handleLogin = async () => {
|
||||
let value = "xxx"
|
||||
await setToken(value)
|
||||
token.value = value
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
const handleLogout = async () => {
|
||||
await logout()
|
||||
token.value = null
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
token.value = await getToken()
|
||||
})
|
||||
|
||||
return {
|
||||
isLoggedIn,
|
||||
handleLogin,
|
||||
handleLogout,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user