Menu

Nothing in our code creates an anonymous session, and eleven route handlers have five different answers for one
📰

Nothing in our code creates an anonymous session, and eleven route handlers have five different answers for one

DEV Community: nextjs·Daniel Pertu·4 days ago
#1OpE3ozi
#devtonextjs#devto#dev#session#user
Reading 0:00
15s threshold

Munchable is a gut-condition barcode scanner whose server deliberately holds almost nothing: an email address, a subscription record, and any product labels you contributed. The policy is at munchable.app/privacy . Every one of its 29 route handlers starts the same way.

const user = await getUser ( request ) ; if ( ! user ) return NextResponse . json ( { error : 'unauthorized' } , { status : 401 } ) ;

Enter fullscreen mode

Exit fullscreen mode

Eleven of them then do something else, and the something else is the subject of this post:

if ( user . isAnonymous ) { return NextResponse . json ( { error : 'account_required' } , { status : 403 } ) ; }

Enter fullscreen mode

Exit fullscreen mode

Twenty-one references to isAnonymous across thirteen files. And then:

$ grep -rn "signInAnonymously" apps packages $ echo $?…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.