Skip to content

Commit

Permalink
Move UserAccount interface in dedicated file
Browse files Browse the repository at this point in the history
  • Loading branch information
e-adrien committed Dec 4, 2024
1 parent 4dabe4e commit faf6587
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions server/@types/express/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UserAccount } from "../../middlewares/authentication";
import { UserAccount } from "../../interfaces/index.js";

export {};

Expand All @@ -21,7 +21,7 @@ declare module "express-session" {
interface SessionData {
passport:
| {
user: string | UserAccount | undefined;
user: UserAccount | string | undefined;
}
| undefined;
}
Expand Down
3 changes: 3 additions & 0 deletions server/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type UserAccount = {
username: string;
};
7 changes: 2 additions & 5 deletions server/middlewares/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NextFunction, Request, Response, Router } from "express";
import nconf from "nconf";
import passport from "passport";
import { Strategy as LocalStrategy } from "passport-local";
import { UserAccount } from "../interfaces/index.js";

export const kUrlLoginPage = "/auth/login";
export const kUrlLogoutPage = "/auth/logout";
Expand All @@ -18,10 +19,6 @@ type AuthenticateCallback = (
info: { message: string } | undefined
) => void;

export type UserAccount = {
username: string;
};

function checkCredential(username: string, password: string, credential: Credential): boolean {
return (
credential.username === username &&
Expand Down Expand Up @@ -55,7 +52,7 @@ export function authentication() {
);

// Add serializers
passport.serializeUser(function (user: UserAccount, done) {
passport.serializeUser(function (user: UserAccount, done: (err?: Error | null, id?: unknown) => void) {
done(null, user.username);
});
passport.deserializeUser(async function (username: string, done) {
Expand Down

0 comments on commit faf6587

Please sign in to comment.