티스토리 뷰

nodejs cognito 연동하기

 

 

global.fetch = require('node-fetch');

const AmplifyCore = require('aws-amplify')
const Amplify = require('aws-amplify').default
const { API, Auth } = Amplify

const testLogin = (email, password, provider) => {
console.log(email);

let COGNITO = {
REGION: 'us-west-2',
USER_POOL_ID: 'us-west-2_xRKVaj5ls',
CLIENT_ID: '5084o932i7age4c0tc9j2unmff',
}

COGNITO = {
REGION: 'ap-northeast-2',
USER_POOL_ID: 'ap-northeast-2_CHGQe7flY',
CLIENT_ID: '29ilv9idglfh0spnbe9tpfb19m',
}

Amplify.configure({
Auth: {
userPoolId: COGNITO.USER_POOL_ID,
userPoolWebClientId: COGNITO.CLIENT_ID,
region: COGNITO.REGION,
// authenticationFlowType: 'CUSTOM_AUTH',
}
});
Auth.signIn(email, password)
.then(user => {
// console.log(user);
console.log(user.challengeName);
if (user.challengeName) {
const { requiredAttributes } = user.challengeParam; // the array of required attributes, e.g ['email', 'phone_number']
Auth.completeNewPassword(
user, // the Cognito User Object
"1234@Aoeuu", // the new password
// OPTIONAL, the required attributes
{
email: 'aa@example.com',
phone_number: '+1234567890'
}
).then(user => {
// at this time the user is logged in if no MFA required
console.log(user);
}).catch(e => {
console.log(e);
});

}
})
.catch(err => console.log("err:", err));
};


const callCognito = (userId, password, cb) => {
const email = userId;
const COGNITO2 = {
REGION: 'ap-northeast-2',
USER_POOL_ID: 'ap-northeast-2_CHGQe7flY',
CLIENT_ID: '29ilv9idglfh0spnbe9tpfb19m',
}

testLogin(userId, password, () => {
});

}


module.exports.callCognito = callCognito;

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함