yo-next-auth/config/routes.ts

50 lines
1.8 KiB
TypeScript

import { UUID_V4_REGEX } from '@/config/validation'
export const USER_PROFILE_URL: string = '/cabinet'
export const USER_SERVER_URL: string = `${USER_PROFILE_URL}/server`
export const USER_CLIENT_URL: string = `${USER_PROFILE_URL}/client`
export const USER_ADMIN_URL: string = `${USER_PROFILE_URL}/admin`
export const AUTH_URL: string = '/auth/'
export const AUTH_LOGIN_URL: string = `${AUTH_URL}login`
export const AUTH_REGISTER_URL: string = `${AUTH_URL}register`
export const AUTH_RESET_PASSWORD_URL: string = `${AUTH_URL}reset`
export const AUTH_ERROR_URL: string = `${AUTH_URL}error`
export const AUTH_USER_VERIFICATION_URL: string = `${AUTH_URL}user-verification`
export const AUTH_NEW_PASSWORD_URL: string = `${AUTH_URL}new-password`
export const CABINET_ROUTES: string[] = [USER_SERVER_URL, USER_CLIENT_URL, USER_ADMIN_URL, USER_PROFILE_URL] as const
/**
* An array of routes that accessible to the public.
* These routes do not requite authentication.
* @type {string[]}
*/
export const publicRoutes: string[] = [
'/', '/((about)(|/.*))', `(${AUTH_USER_VERIFICATION_URL}|${AUTH_NEW_PASSWORD_URL})/${UUID_V4_REGEX}`]
/**
* An array of routes that are used for authentication.
* These routes will redirect logged-in users to /cabinet
* @type {string[]}
*/
export const authRoutes: string[] = [
AUTH_LOGIN_URL, AUTH_REGISTER_URL, AUTH_ERROR_URL, AUTH_RESET_PASSWORD_URL]
export const authRoutesRegEx = [
AUTH_URL + '(' +
authRoutes.map((uri: string) => uri.replace(AUTH_URL, '')).join('|') + ')']
/**
* The prefix for API authentication routes.
* Routes that start with this prefix are used for API authentication purposes.
* @type {string}
*/
export const apiAuthPrefixRegEx: string = '/api/(auth|admin)'
/**
* The default redirect path after logging in.
* @type {string}
*/
export const DEFAULT_LOGIN_REDIRECT: string = USER_PROFILE_URL