| 1 | import type { NextRequest } from 'next/server' |
| 2 | |
| 3 | export const PUBLIC_ROUTES: |
| 4 | '/', |
| 5 | '/api/og', |
| 6 | '/polar/webhooks', |
| 7 | '/opengraph-image.png', |
| 8 | '/twitter-image.png', |
| 9 | '/sitemap.xml', |
| 10 | '/manifest.webmanifest', |
| 11 | '/terms', |
| 12 | '/privacy', |
| 13 | ] |
| 14 | export const PUBLIC_PREFIXES: |
| 15 | export const AUTH_PREFIX: |
| 16 | export const API_AUTH_PREFIX: |
| 17 | export const ERROR_PREFIX: |
| 18 | export const DEFAULT_LOGIN_REDIRECT: |
| 19 | |
| 20 | export function isApiAuth(pathname |
| 21 | return startsWith(pathname |
| 22 | } |
| 23 | |
| 24 | export function isAuthRoute(pathname |
| 25 | return startsWith(pathname |
| 26 | } |
| 27 | |
| 28 | export function isPublicRoute(pathname |
| 29 | return ( |
| 30 | isPathEqual(pathname, PUBLIC_ROUTES |
| 31 | startsWith(pathname, ERROR_PREFIX |
| 32 | PUBLIC_PREFIXES.some((p |
| 33 | ) |
| 34 | } |
| 35 | |
| 36 | // Utils |
| 37 | function isPathEqual(pathname: |
| 38 | return paths.includes |
| 39 | } |
| 40 | |
| 41 | function startsWith(pathname: |
| 42 | return pathname.startsWith |
| 43 | } |
| 44 | |
| 45 | export function getSignInUrl(request |
| 46 | const rt = |
| 47 | return new URL |
| 48 | `${AUTH_PREFIX}/sign-in?redirectTo=${encodeURIComponent |
| 49 | request.url |
| 50 | ) |
| 51 | } |