TELYA
04/19/2022, 11:47 PMtypescript
await EmailPasswordReact.signOut();
await EmailPasswordReact.redirectToAuth({ show: "signin" });
And it cleared all my cookies and redirected to the login page. It was pretty much it, but i noticed, that after i added a change password functionality to my site and after i successfully changed my password the EmailPasswordReact.signOut function call didn't cleared my cookies. I had to delete them manually then after a relogging, it worked just as before.
I checked my backend(Nest.js) code and it seems fine
typescript
@Post("/change-password")
@UseGuards(AuthGuard)
async changePassword(
@Session() session: SessionContainer,
@Body() changePasswordDto: ChangePasswordDto,
@Res() res: Response
) {
const { currentPassword, newPassword } = changePasswordDto;
const userId = session.getUserId();
const userInfo = await EmailPasswordNode.getUserById(userId);
if (userInfo === undefined) {
throw new Error("Should never come here");
}
const isPasswordValid = await EmailPasswordNode.signIn(userInfo.email, currentPassword);
if (isPasswordValid.status !== "OK") {
throw new BadRequestException("Hibás jelenlegi jelszó");
}
const response = await EmailPasswordNode.updateEmailOrPassword({
userId,
password: newPassword
}).catch((error) => {
console.log(error);
throw new InternalServerErrorException("Váratlan hiba");
});
if (response.status !== "OK") {
throw new InternalServerErrorException("Váratlan hiba");
}
await SupertokensSession.revokeAllSessionsForUser(userId);
await session.revokeSession();
return res.status(401);
}
Do you guys have any idea what i did wrong ?
Thanks for the answers in advance 🙂rp
04/20/2022, 3:42 AMTELYA
04/20/2022, 9:13 AMawait EmailPasswordReact.signOut();
and the
await EmailPasswordReact.redirectToAuth({ show: "signin" });
because like you said i only need a 401 unauthorized response back from my backend.
The problem was in Nestjs the return res.status(401);
didn't work so i replaced it to throw new UnauthorizedException();
and it worked perfectly.
I wanna say thanks to your thoughts. It really helped me find out what was wrong 🙂redirectToPath=%2Fprofile
because i was in profile page. Can i change this somehow, because after password change i login back and got redirected back to the /profile
page but i would like to go /
instead.rp
04/20/2022, 11:08 AMTELYA
04/20/2022, 11:22 AM