Files
JayuCloud/JY-Artist-Frontend/src/api/auth-free-paths.ts
T
2026-06-29 23:26:43 +08:00

85 lines
3.2 KiB
TypeScript

/**
* Purpose: WEB_API_AUTH_FREE_PATHS supports auth-free-paths.ts by holding or executing the web api auth free paths page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
export const WEB_API_AUTH_FREE_PATHS = [
'/user/login',
'/user/register',
'/user/check/',
'/user/refresh-token',
'/user/send-verification-code',
'/user/phone-login',
'/user/wechat-mini/',
'/user/reset-password-by-phone',
'/legal-agreement/current',
'/api/legal-agreement/current',
'/product/get/',
'/product/list/',
'/comment/list/product/',
'/nail-artist/',
'/shop/get/',
'/shop/trust-profile/',
'/shop/list',
'/shop/list/public',
'/shop/list/simple',
'/tag/list/all',
'/tag/list/filter-options',
'/file/get-signed-url/',
'/admin/auth/login',
'/admin/auth/login-shops/',
'/admin/auth/refresh'
] as const
/**
* Purpose: ADMIN_API_AUTH_FREE_PATHS supports auth-free-paths.ts by holding or executing the admin api auth free paths page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
export const ADMIN_API_AUTH_FREE_PATHS = [
'/auth/login',
'/auth/login-shops/',
'/auth/refresh'
] as const
/**
* Purpose: normalizePathname supports auth-free-paths.ts by holding or executing the normalize pathname page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const normalizePathname = (url?: string) => {
const raw = String(url || '')
const withoutHash = raw.split('#')[0] || ''
const withoutQuery = withoutHash.split('?')[0] || ''
try {
return new URL(withoutQuery, 'http://jayucloud.local').pathname
} catch {
return withoutQuery.startsWith('/') ? withoutQuery : `/${withoutQuery}`
}
}
/**
* Purpose: matchesAuthFreePath supports auth-free-paths.ts by holding or executing the matches auth free path page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const matchesAuthFreePath = (url: string | undefined, path: string) => {
const pathname = normalizePathname(url)
if (path.endsWith('/')) {
return pathname === path.slice(0, -1) || pathname.startsWith(path)
}
return pathname === path
}
/**
* Purpose: isApiAuthFreePath supports auth-free-paths.ts by holding or executing the is api auth free path page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
export const isApiAuthFreePath = (url?: string) => {
return WEB_API_AUTH_FREE_PATHS.some(path => matchesAuthFreePath(url, path))
}
/**
* Purpose: isAdminApiAuthFreePath supports auth-free-paths.ts by holding or executing the is admin api auth free path page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
export const isAdminApiAuthFreePath = (url?: string) => {
return ADMIN_API_AUTH_FREE_PATHS.some(path => matchesAuthFreePath(url, path))
}