Skip to content
This repository was archived by the owner on Sep 25, 2025. It is now read-only.

Commit 1dd0104

Browse files
committed
updated Backend
1 parent 2eae1bc commit 1dd0104

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

backend/functions/user/myInfo.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
11
import { CognitoIdentityProviderClient, GetUserCommand } from '@aws-sdk/client-cognito-identity-provider'
2-
import { APIGatewayProxyEventV2WithJWTAuthorizer, APIGatewayProxyResultV2 } from 'aws-lambda'
2+
import { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from 'aws-lambda'
33
import { error, internalServerError, unAuthorized } from '../../utils/httpError'
44

55
const cognitoClient = new CognitoIdentityProviderClient({})
66

7-
export const handler = async (event: APIGatewayProxyEventV2WithJWTAuthorizer): Promise<APIGatewayProxyResultV2> => {
7+
export const handler = async (event: APIGatewayProxyEventV2): Promise<APIGatewayProxyResultV2> => {
88
try {
99
const authHeader = event.headers?.Authorization ?? event.headers?.authorization
1010

11-
if (!authHeader || !authHeader.startsWith('Bearer '))
12-
return {
13-
statusCode: 401,
14-
body: JSON.stringify({
15-
error: 'Unauthorized',
16-
message: 'No valid authorization header provided',
17-
}),
18-
}
11+
if (!authHeader || !authHeader.startsWith('Bearer ')) return error(unAuthorized(), 'ERR_GET_USER_UNAUTHORIZED')
1912

2013
const accessToken = authHeader.substring('Bearer '.length)
2114

2215
const getUserCommand = new GetUserCommand({ AccessToken: accessToken })
23-
const response = await cognitoClient.send(getUserCommand)
16+
const result = await cognitoClient.send(getUserCommand)
2417

25-
const userAttributes = Object.fromEntries(
26-
(response.UserAttributes ?? []).map((attr) => [attr.Name, attr.Value])
27-
)
18+
const userAttributes = Object.fromEntries((result.UserAttributes ?? []).map((attr) => [attr.Name, attr.Value]))
2819

2920
return {
3021
statusCode: 200,
3122
body: JSON.stringify({
32-
username: response.Username,
23+
username: result.Username,
3324
...userAttributes,
3425
}),
3526
}

0 commit comments

Comments
 (0)