Implement authentication using Passport.js

This commit is contained in:
Aaron William Po
2023-02-05 19:27:19 -05:00
parent 86f6f9abc5
commit 087a1a4513
26 changed files with 2073 additions and 412 deletions

25
config/auth/types.ts Normal file
View File

@@ -0,0 +1,25 @@
import { IncomingMessage } from 'http';
import { NextApiRequest } from 'next';
import { z } from 'zod';
export const UserInfoSchema = z.object({
id: z.string().uuid(),
username: z.string(),
});
export const UserSessionSchema = UserInfoSchema.merge(
z.object({
createdAt: z.number(),
maxAge: z.number(),
}),
);
export interface ExtendedNextApiRequest extends NextApiRequest {
user?: z.infer<typeof UserInfoSchema>;
}
export type SessionRequest = IncomingMessage & {
cookies: Partial<{
[key: string]: string;
}>;
};