File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { getLlmResponse } from '../logic/ai3.ts';
33import type { Message } from '../logic/ai3.ts' ;
44import { getChat , saveChat } from '../logic/database.ts' ;
55import { sendMessage } from './api/sse.ts' ;
6+ import { parseAuthToken } from '../auth.ts' ;
67
78export async function POST ( context : APIContext ) {
89
@@ -27,8 +28,16 @@ export async function POST(context: APIContext) {
2728 }
2829 }
2930
31+ // get user email from JWT
32+ const oidcDataToken = context . request . headers . get ( 'x-amzn-oidc-data' ) || '' ;
33+ const { email : userEmail } = await parseAuthToken ( oidcDataToken ) ;
34+
35+ if ( ! userEmail ) {
36+ console . error ( 'No user email found in token' ) ;
37+ return new Response ( 'Unauthorized: No user email in token' , { status : 401 } ) ;
38+ }
39+
3040 // add user prompt to session data
31- const userEmail = await context . session ?. get ( 'user-email' ) ;
3241 let messages : Message [ ] | undefined = ( await getChat ( userEmail , chatId ) ) ?. messages ;
3342 if ( ! messages ) {
3443 messages = [ ] ;
You can’t perform that action at this time.
0 commit comments