yo-next-auth/config/routes.ts

44 lines
1.4 KiB
TypeScript

import { locales } from '@/config/locales'
export const USER_PROFILE_URL: string = '/cabinet'
export const AUTH_LOGIN_URL: string = '/auth/login'
export const AUTH_REGISTER_URL: string = '/auth/register'
export const AUTH_ERROR_URL: string = '/auth/error'
export const AUTH_EMAIL_VERIFICATION_URL: string = '/auth/email-verification'
/**
* An array of routes that accessible to the public.
* These routes do not requite authentication.
* @type {string[]}
*/
export const publicRoutes: string[] = [
'/', '/about']
/**
* 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_EMAIL_VERIFICATION_URL]
/**
* 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
export const testPathnameRegex = (
pages: string[], pathName: string): boolean => {
const pattern: string = `^(/(${locales.join('|')}))?(${pages.flatMap(
(p) => (p === '/' ? ['', '/'] : p)).join('|')})/?$`
return RegExp(pattern, 'is').test(pathName)
}