mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
25 lines
683 B
TypeScript
25 lines
683 B
TypeScript
//-- User sessions helper
|
|
|
|
import { Request } from "express";
|
|
import CookieSessionObject = CookieSessionInterfaces.CookieSessionObject;
|
|
|
|
interface IUserSession extends CookieSessionObject {
|
|
authHeader: string;
|
|
username?: string;
|
|
isUserLogin?: boolean; // authorization via user's manual login with credentials
|
|
}
|
|
|
|
export const userSession = {
|
|
get(req: Request): Partial<IUserSession> {
|
|
return req.session;
|
|
},
|
|
save(req: Request, data: Partial<IUserSession> = {}) {
|
|
Object.assign(req.session, data);
|
|
},
|
|
getToken(req: Request): string {
|
|
const { authHeader = "" } = this.get(req);
|
|
const [type, token = ""] = authHeader.split(" ");
|
|
return token;
|
|
}
|
|
};
|