Add post and tag review workflow

This commit is contained in:
Tim
2025-07-11 14:04:33 +08:00
parent a991b20f9c
commit 9a5a1df420
13 changed files with 192 additions and 23 deletions

View File

@@ -4,16 +4,19 @@ import { reactive } from 'vue'
const TOKEN_KEY = 'token'
const USER_ID_KEY = 'userId'
const USERNAME_KEY = 'username'
const ROLE_KEY = 'role'
export const authState = reactive({
loggedIn: false,
userId: null,
username: null
username: null,
role: null
})
authState.loggedIn = localStorage.getItem(TOKEN_KEY) !== null && localStorage.getItem(TOKEN_KEY) !== ''
authState.userId = localStorage.getItem(USER_ID_KEY)
authState.username = localStorage.getItem(USERNAME_KEY)
authState.role = localStorage.getItem(ROLE_KEY)
export function getToken() {
return localStorage.getItem(TOKEN_KEY)
@@ -33,6 +36,10 @@ export function clearToken() {
export function setUserInfo({ id, username }) {
authState.userId = id
authState.username = username
if (arguments[0] && arguments[0].role) {
authState.role = arguments[0].role
localStorage.setItem(ROLE_KEY, arguments[0].role)
}
if (id !== undefined && id !== null) localStorage.setItem(USER_ID_KEY, id)
if (username) localStorage.setItem(USERNAME_KEY, username)
}
@@ -40,8 +47,10 @@ export function setUserInfo({ id, username }) {
export function clearUserInfo() {
localStorage.removeItem(USER_ID_KEY)
localStorage.removeItem(USERNAME_KEY)
localStorage.removeItem(ROLE_KEY)
authState.userId = null
authState.username = null
authState.role = null
}
export async function fetchCurrentUser() {
@@ -61,7 +70,7 @@ export async function fetchCurrentUser() {
export async function loadCurrentUser() {
const user = await fetchCurrentUser()
if (user) {
setUserInfo({ id: user.id, username: user.username })
setUserInfo({ id: user.id, username: user.username, role: user.role })
}
return user
}