feat:登录的功能完成
This commit is contained in:
19
src/utils/auth-guard.ts
Normal file
19
src/utils/auth-guard.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { getAccessToken } from '@/utils/auth-storage'
|
||||
|
||||
export const LOGIN_PAGE = '/pages/Login/user-login/index'
|
||||
|
||||
export function isLoggedIn() {
|
||||
return Boolean(getAccessToken())
|
||||
}
|
||||
|
||||
/** 未登录时跳转登录页,返回是否已登录 */
|
||||
export function ensureLoggedIn(showToast = true) {
|
||||
if (isLoggedIn())
|
||||
return true
|
||||
|
||||
if (showToast)
|
||||
uni.showToast({ title: '请先登录', icon: 'none' })
|
||||
|
||||
uni.reLaunch({ url: LOGIN_PAGE })
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user