mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-02 09:22:15 +00:00
fix(auth): start no new session for a password change over a Bearer token
A password change ends every session of the user and re-issues one for the device it was made on, handed out as the session cookie. A caller that authenticated with a Bearer token never reads that cookie, so the new session sat in the session list as a live device nobody held until it expired. The controller now asks for the replacement session only when the request came with the session cookie, the same check the sliding renewal makes. The response body is unchanged.
This commit is contained in:
@@ -111,10 +111,14 @@ export class AuthController {
|
||||
async changePassword(@CurrentUser() user: User, @Body() body: ChangePasswordDto, @Req() req: Request, @Res({ passthrough: true }) res: Response) {
|
||||
await this.limit('login', req, 5);
|
||||
// Carry the session's remember choice into the re-issued token/cookie so a
|
||||
// "remember me" login survives a password change (#1927). Bearer callers
|
||||
// have no cookie → undefined → the historical default duration.
|
||||
const remember = decodeSessionClaims((req.cookies as Record<string, string> | undefined)?.trek_session)?.remember;
|
||||
const result = await this.auth.changePassword(user.id, user.email, body, remember, sessionClientFrom(req));
|
||||
// "remember me" login survives a password change (#1927). The guard
|
||||
// verified the cookie whenever there is one (extractToken prefers it), the
|
||||
// same check the renewal interceptor makes. A Bearer caller has none: it
|
||||
// would never see a re-issued token, so no new session is started for it.
|
||||
const cookie = (req.cookies as Record<string, string> | undefined)?.trek_session;
|
||||
const remember = decodeSessionClaims(cookie)?.remember;
|
||||
const cookieSession = typeof cookie === 'string' && cookie.length > 0;
|
||||
const result = await this.auth.changePassword(user.id, user.email, body, remember, sessionClientFrom(req), cookieSession);
|
||||
if (result.error) {
|
||||
throw new HttpException({ error: result.error }, result.status!);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user