1 | import { AuthenticationDetails, CognitoUserSession } from 'amazon-cognito-identity-js'
|
2 | import type { session_user_ctx_type } from './session_user_ctx_type'
|
3 | import { _cognito_user } from './_cognito_user'
|
4 | export async function authenticateUser(Username:string, Password:string):Promise<session_user_ctx_type> {
|
5 | const AuthenticationDetails__ = new AuthenticationDetails({
|
6 | Username,
|
7 | Password,
|
8 | })
|
9 | const user = _cognito_user(Username)
|
10 | return new Promise((resolve, reject)=>{
|
11 | user.authenticateUser(AuthenticationDetails__, {
|
12 | onSuccess(session:CognitoUserSession) {
|
13 | resolve({ session, user })
|
14 | },
|
15 | onFailure(err) {
|
16 | reject(err.message || JSON.stringify(err))
|
17 | },
|
18 | })
|
19 | })
|
20 | }
|