数据库文档编写,开发规范文档,数据库接入
This commit is contained in:
20
services/analytics/authGuard.uts
Normal file
20
services/analytics/authGuard.uts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { getUserIdOrNull } from './auth.uts'
|
||||
import { toLoginWithRedirect, getCurrentPageUrlWithQuery } from '@/utils/authRedirect.uts'
|
||||
|
||||
export type EnsureLoginOptions = {
|
||||
redirectUrl?: string
|
||||
toastTitle?: string
|
||||
}
|
||||
|
||||
export function ensureAnalyticsLogin(opts?: EnsureLoginOptions): boolean {
|
||||
const uid = getUserIdOrNull()
|
||||
if (uid != null && uid !== '') return true
|
||||
|
||||
const target = (opts?.redirectUrl != null && opts?.redirectUrl?.length > 0)
|
||||
? opts?.redirectUrl as string
|
||||
: getCurrentPageUrlWithQuery()
|
||||
|
||||
uni.showToast({ title: opts?.toastTitle ?? '请先登录', icon: 'none' })
|
||||
toLoginWithRedirect(target)
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user