| 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 | ] |
| 12 | export const AUTH_PREFIX: |
| 13 | export const API_AUTH_PREFIX: |
| 14 | export const ERROR_PREFIX: |
| 15 | export const DEFAULT_LOGIN_REDIRECT: |
| 16 | |
| 17 | export function isApiAuth(pathname |
| 18 | return startsWith(pathname |
| 19 | } |
| 20 | |
| 21 | export function isAuthRoute(pathname |
| 22 | return startsWith(pathname |
| 23 | } |
| 24 | |
| 25 | export function isPublicRoute(pathname |
| 26 | return ( |
| 27 | isPathEqual(pathname, PUBLIC_ROUTES |
| 28 | ) |
| 29 | } |
| 30 | |
| 31 | // Utils |
| 32 | function isPathEqual(pathname: |
| 33 | return paths.includes |
| 34 | } |
| 35 | |
| 36 | function startsWith(pathname: |
| 37 | return pathname.startsWith |
| 38 | } |
| 39 | |
| 40 | export function getSignInUrl(request |
| 41 | const rt = |
| 42 | return new URL |
| 43 | `${AUTH_PREFIX}/sign-in?redirectTo=${encodeURIComponent |
| 44 | request.url |
| 45 | ) |
| 46 | } |