Kakao web auth api client
카카오 웹 로그인 구현
npm i --save kakao-web
import { AuthApiClient } from 'kakao-web';
async function main() {
const apiClient = await AuthApiClient.create({
serviceURL: 'https://example.com',
});
const res = await apiClient.login({
email: 'email@example.com',
password: 'password',
});
console.log(res);
}
main();
import { AuthApiClient, LoginStatus } from 'kakao-web';
async function main() {
const apiClient = await AuthApiClient.create({
serviceURL: 'https://example.com',
});
const res = await apiClient.login({
email: 'email@example.com',
password: 'password',
});
if (res.response.status === LoginStatus.TWO_FACTOR) {
console.log('need two-step verification');
const { token, expireSeconds } = await apiClient.sendTwoFactor('tms');
console.log('token: ', token);
const loop = setInterval(async () => {
const { response, cookieJar } = await apiClient.verifyTwoFactor('tms', {
token,
});
if (response.status === LoginStatus.SUCCESS) {
console.log('success!');
console.log(cookieJar);
process.exit(0);
} else if (response.status !== LoginStatus.TWO_FACTOR) {
console.error(`error with status ${response.status}`);
process.exit(1);
}
}, 1000);
setTimeout(() => {
clearInterval(loop);
console.log('timeout!');
process.exit(1);
}, expireSeconds * 1000);
} else if (res.response.status === LoginStatus.SUCCESS) {
console.log(res);
}
}
main()