Express.d.ts: normalize session fields case

This commit is contained in:
Alice Gaudon 2021-01-25 10:53:43 +01:00
parent e4768141bc
commit f1a8a4ba07
3 changed files with 11 additions and 11 deletions

View File

@ -63,7 +63,7 @@ export default class AuthGuard {
}
public async getProofsForSession(session: Session & Partial<SessionData>): Promise<AuthProof<User>[]> {
if (!session.is_authenticated) return [];
if (!session.isAuthenticated) return [];
const proofs = [];
for (const method of this.authMethods) {
@ -80,7 +80,7 @@ export default class AuthGuard {
}
if (proofs.length === 0) {
session.is_authenticated = false;
session.isAuthenticated = false;
session.persistent = false;
}
@ -152,7 +152,7 @@ export default class AuthGuard {
}
// Login
session.is_authenticated = true;
session.isAuthenticated = true;
session.persistent = persistSession;
if (onLogin) await onLogin(user);

View File

@ -6,7 +6,7 @@ import {Session, SessionData} from "express-session";
export default class PasswordAuthProof implements AuthProof<User> {
public static getProofForSession(session: Session & Partial<SessionData>): PasswordAuthProof | null {
return session.auth_password_proof ? new PasswordAuthProof(session) : null;
return session.authPasswordProof ? new PasswordAuthProof(session) : null;
}
public static createAuthorizedProofForRegistration(session: Session): PasswordAuthProof {
@ -29,9 +29,9 @@ export default class PasswordAuthProof implements AuthProof<User> {
private constructor(session: Session & Partial<SessionData>) {
this.session = session;
this.authorized = session.auth_password_proof?.authorized || false;
this.forRegistration = session.auth_password_proof?.forRegistration || false;
this.userId = session.auth_password_proof?.userId || null;
this.authorized = session.authPasswordProof?.authorized || false;
this.forRegistration = session.authPasswordProof?.forRegistration || false;
this.userId = session.authPasswordProof?.userId || null;
}
public async getResource(): Promise<User | null> {
@ -54,7 +54,7 @@ export default class PasswordAuthProof implements AuthProof<User> {
}
public async revoke(): Promise<void> {
this.session.auth_password_proof = undefined;
this.session.authPasswordProof = undefined;
}
private async getUserPassword(): Promise<UserPasswordComponent | null> {
@ -74,7 +74,7 @@ export default class PasswordAuthProof implements AuthProof<User> {
}
private save() {
this.session.auth_password_proof = {
this.session.authPasswordProof = {
authorized: this.authorized,
forRegistration: this.forRegistration,
userId: this.userId,

View File

@ -45,9 +45,9 @@ declare module 'express-session' {
persistent?: boolean;
is_authenticated?: boolean;
isAuthenticated?: boolean;
auth_password_proof?: PasswordAuthProofSessionData;
authPasswordProof?: PasswordAuthProofSessionData;
csrf?: string;
}