File tree Expand file tree Collapse file tree 3 files changed +24
-20
lines changed
app/api/auth/forget-password Expand file tree Collapse file tree 3 files changed +24
-20
lines changed Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ describe('Forget Password API Route', () => {
7272 const data = await response . json ( )
7373
7474 expect ( response . status ) . toBe ( 400 )
75- expect ( data . message ) . toBe ( 'Redirect URL must be same-origin' )
75+ expect ( data . message ) . toBe ( 'Redirect URL must be a valid same-origin URL ' )
7676
7777 const auth = await import ( '@/lib/auth' )
7878 expect ( auth . auth . api . forgetPassword ) . not . toHaveBeenCalled ( )
Original file line number Diff line number Diff line change @@ -14,13 +14,15 @@ const forgetPasswordSchema = z.object({
1414 . email ( 'Please provide a valid email address' ) ,
1515 redirectTo : z
1616 . string ( )
17- . url ( 'Redirect URL must be a valid URL' )
18- . refine ( ( url ) => isSameOrigin ( url ) , {
19- message : 'Redirect URL must be same-origin' ,
20- } )
2117 . optional ( )
2218 . or ( z . literal ( '' ) )
23- . transform ( ( val ) => ( val === '' ? undefined : val ) ) ,
19+ . transform ( ( val ) => ( val === '' || val === undefined ? undefined : val ) )
20+ . refine (
21+ ( val ) => val === undefined || ( z . string ( ) . url ( ) . safeParse ( val ) . success && isSameOrigin ( val ) ) ,
22+ {
23+ message : 'Redirect URL must be a valid same-origin URL' ,
24+ }
25+ ) ,
2426} )
2527
2628export async function POST ( request : NextRequest ) {
Original file line number Diff line number Diff line change 11/**
22 * Environment utility functions for consistent environment detection across the application
33 */
4-
5- import { createLogger } from '@/lib/logs/console/logger'
64import { env , getEnv , isTruthy } from './env'
75
8- const logger = createLogger ( 'FeatureFlags' )
9-
106/**
117 * Is the application running in production mode
128 */
@@ -46,16 +42,22 @@ export const isEmailVerificationEnabled = isTruthy(env.EMAIL_VERIFICATION_ENABLE
4642export const isAuthDisabled = isTruthy ( env . DISABLE_AUTH ) && ! isHosted
4743
4844if ( isTruthy ( env . DISABLE_AUTH ) ) {
49- if ( isHosted ) {
50- logger . error (
51- 'DISABLE_AUTH is set but ignored on hosted environment. Authentication remains enabled for security.'
52- )
53- } else {
54- logger . warn (
55- 'DISABLE_AUTH is enabled. Authentication is bypassed and all requests use an anonymous session. ' +
56- 'Only use this in trusted private networks.'
57- )
58- }
45+ import ( '@/lib/logs/console/logger' )
46+ . then ( ( { createLogger } ) => {
47+ const logger = createLogger ( 'FeatureFlags' )
48+ if ( isHosted ) {
49+ logger . error (
50+ 'DISABLE_AUTH is set but ignored on hosted environment. Authentication remains enabled for security.'
51+ )
52+ } else {
53+ logger . warn (
54+ 'DISABLE_AUTH is enabled. Authentication is bypassed and all requests use an anonymous session. Only use this in trusted private networks.'
55+ )
56+ }
57+ } )
58+ . catch ( ( ) => {
59+ // Fallback during config compilation when logger is unavailable
60+ } )
5961}
6062
6163/**
You can’t perform that action at this time.
0 commit comments