File tree Expand file tree Collapse file tree 2 files changed +15
-6
lines changed
Expand file tree Collapse file tree 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ interface ChatRouteRequest {
7272}
7373
7474export async function POST ( req : Request ) {
75- const authorized = await checkAuthorizedStatus ( ) ;
75+ const authorized = await checkAuthorizedStatus ( [ "*" , "ai" ] ) ;
7676 if ( ! authorized ) {
7777 return new NextResponse ( "Unauthorized" , { status : 401 } ) ;
7878 }
Original file line number Diff line number Diff line change @@ -17,17 +17,26 @@ export async function redirectIfAuthenticated(): Promise<void> {
1717 redirect ( "/" ) ;
1818}
1919
20- export async function checkAuthorizedStatus ( ) : Promise < boolean > {
20+ export async function checkAuthorizedStatus ( requiredScopes ?: string [ ] ) : Promise < boolean > {
2121 const token = await getAuthToken ( ) ;
2222 if ( ! token ) {
2323 return false ;
2424 }
2525
26- const loggedIn = await getAuthStatus ( token )
27- . then ( result => result . loggedIn )
28- . catch ( ( ) => false ) ;
26+ const authStatus = await getAuthStatus ( token ) ;
27+
28+ if ( ! authStatus . loggedIn || ! authStatus . introspectResult ?. active ) {
29+ return false ;
30+ }
31+
32+ // check if the token has the required scope
33+ if ( requiredScopes ) {
34+ for ( const scope of requiredScopes ) {
35+ if ( authStatus . introspectResult ?. scope . includes ( scope ) ) {
36+ return true ;
37+ }
38+ }
2939
30- if ( ! loggedIn ) {
3140 return false ;
3241 }
3342
You can’t perform that action at this time.
0 commit comments