📦 EqualifyEverything / equalify

📄 authenticate.ts · 22 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22import { cognito, event } from '#src/utils'

export const authenticate = async () => {
    const { email, password } = event.body;
    try {
        const authResponse = await cognito.adminInitiateAuth({
            UserPoolId: process.env.USER_POOL_ID,
            ClientId: process.env.WEB_CLIENT_ID,
            AuthFlow: 'ADMIN_USER_PASSWORD_AUTH',
            AuthParameters: {
                USERNAME: email,
                PASSWORD: password,
            },
        });
        const accessToken = authResponse.AuthenticationResult.IdToken;

        return { accessToken };
    }
    catch (err) {
        return { message: err }
    }
}