Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"sentry:sourcemaps": "sentry-cli sourcemaps inject --org $SENTRY_ORG --project $SENTRY_PROJECT ./dist && sentry-cli sourcemaps upload --org $SENTRY_ORG --project $SENTRY_PROJECT ./dist"
},
"dependencies": {
"@prisma/client": "^6.6.0",
"@prisma/adapter-pg": "^6.15.0",
"@prisma/client": "^6.15.0",
"@sentry/cli": "^2.43.0",
"@sentry/node": "^9.12.0",
"connect-pg-simple": "^9.0.1",
Expand Down Expand Up @@ -52,7 +53,7 @@
"dotenv-cli": "^7.4.2",
"nodemon": "^3.1.3",
"prettier": "^3.3.2",
"prisma": "^6.6.0",
"prisma": "^6.15.0",
"prisma-dbml-generator": "^0.12.0",
"prisma-docs-generator": "^0.8.0",
"prisma-erd-generator": "^2.0.4",
Expand Down
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["postgresqlExtensions", "views", "relationJoins"]
previewFeatures = ["postgresqlExtensions", "views", "relationJoins", "queryCompiler", "driverAdapters"]
}

generator docs {
Expand Down
26 changes: 17 additions & 9 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,22 @@ passport.serializeUser((user, done) => {
done(null, user.id);
});

passport.deserializeUser(async (id: string, done) => {
const deserializeUser = async (id: string, done: (err: any, user?: User | null) => void) => {
const user = await prisma.user.findUnique({ where: { id: id } });
done(null, user);
});
};

passport.deserializeUser(deserializeUser);

// Serve the static files to be accessed by the docs app
app.use(express.static(path.join(__dirname, '..', 'docs')));

// Public Endpoints
app.get(`${API_URL}`, (req, res) => {
const welcomeApi = (req: Request, res: Response) => {
return res.status(200).send('Welcome to the TEACHING-WEBSITE-API V1.0');
});
};

// Public Endpoints
app.get(`${API_URL}`, welcomeApi);

const SessionOauthStrategy = (req: Request, res: Response, next: NextFunction) => {
if (req.isAuthenticated()) {
Expand All @@ -113,7 +117,7 @@ const SessionOauthStrategy = (req: Request, res: Response, next: NextFunction) =
passport.authenticate('oauth-bearer', { session: true })(req, res, next);
};

app.get(`${API_URL}/checklogin`, SessionOauthStrategy, async (req, res, next) => {
const checkLogin = async (req: Request, res: Response, next: NextFunction) => {
try {
if (req.user) {
return res.status(200).send('OK');
Expand All @@ -122,9 +126,11 @@ app.get(`${API_URL}/checklogin`, SessionOauthStrategy, async (req, res, next) =>
} catch (error) {
next(error);
}
});
};

app.get(`${API_URL}/checklogin`, SessionOauthStrategy, checkLogin);

app.post(`${API_URL}/logout`, async (req, res, next) => {
const logout = async (req: Request, res: Response, next: NextFunction) => {
req.logout({ keepSessionInfo: false }, (err) => {
if (err) {
Logger.error(err);
Expand All @@ -135,7 +141,9 @@ app.post(`${API_URL}/logout`, async (req, res, next) => {
Logger.info(req.session);
// await prisma.sessions.delete({ where: { sid: req.session.id } });
res.clearCookie(SESSION_KEY).send();
});
};

app.post(`${API_URL}/logout`, logout);

export const configure = (_app: typeof app) => {
/**
Expand Down
7 changes: 6 additions & 1 deletion src/prisma.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { PrismaPg } from '@prisma/adapter-pg';
import { Prisma, PrismaClient } from '@prisma/client';

const options: Prisma.PrismaClientOptions & {
Expand All @@ -23,7 +24,11 @@ if (process.env.LOG) {
}
];
}
const prisma = new PrismaClient(options);

const connectionString = `${process.env.DATABASE_URL}`;

const adapter = new PrismaPg({ connectionString });
const prisma = new PrismaClient({ ...options, adapter: adapter });
prisma.$connect();

if (process.env.LOG) {
Expand Down
Loading
Loading