I have a project with Hapi JS and use Bell for provide Sign in with Oauth Google. In handler for Sign up or Sign in, there problem i found it. If user press Cancel button after choose a account (in case user choose wrong email), but throw error like this
{
"statusCode": 500,
"error": "Internal Server Error",
"message": "An internal server error occurred"
}
this error redirect on path http://localhost:9001/user/auth/google?error=access_denied&state=RNVnZeQdAZoBm5kJyWB79p
.
and this is my code
Auth strategy
server.auth.strategy('google', 'bell', {
provider: 'google',
password: PASSWORD_STRATEGY_GOOGLE,
clientId: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
isSecure: false,
});
this is for my route Sign in or up with Google
{
method: ['POST', 'GET'],
path: '/user/auth/google',
handler: handlerGoogleLoginUsers,
options: {
auth: 'google',
cors: true,
plugins: {
'hapi-rate-limit': {
pathLimit: 1,
pathCache: {
expiresIn: 10000,
},
authCache: {
expiresIn: 5000,
},
},
},
},
},
and this for my handler
const handlerGoogleLoginUsers = async (request, h) => {
const { profile } = request.auth.credentials;
const { error } = request.query;
try {
if (error === "access_denied") {
console.log(error);
return h.response({
status: 'fail',
message: 'User cancel it!',
}).code(400);
}
const dataToken = JSON.stringify(profile.raw);
return h.redirect(`/user/api/google/callback?raw=${dataToken}&type=web`);
} catch (err) {
console.error('Terjadi error saat login google: ', err);
return h.response({
status: 'error',
message: 'Terjadi kesalahan, Coba lagi.',
}).code(500);
}
};
"@hapi/bell": "^13.0.2",
"@hapi/hapi": "^21.3.6",
if redirect on http://localhost:9001/user/auth/google?error=access_denied&state=RNVnZeQdAZoBm5kJyWB79p
and this path have a params error
or state
should be catch in my handler.
if (error === "access_denied") {
console.log(error);
return h.response({
status: 'fail',
message: 'User cancel it!',
}).code(400);
}
any idea? or something else?