yo-next-auth/config/routes.ts

45 lines
1.5 KiB
TypeScript

import { UUID_V4_REGEX } from '@/config/validation'
export const USER_PROFILE_URL: string = '/cabinet'
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`
/**
* 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 purpose.
* @type {string}
*/
export const apiAuthPrefix: string = '/api/auth'
/**
* The default redirect path after logging in.
* @type {string}
*/
export const DEFAULT_LOGIN_REDIRECT: string = USER_PROFILE_URL