mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
Update passport/prisma libs
This commit is contained in:
@@ -9,16 +9,30 @@ import {
|
||||
import { Strategy as LocalStrategy } from 'passport-local';
|
||||
import { prisma } from './prisma';
|
||||
|
||||
export const generateToken = (userId: string) => {
|
||||
return jwt.sign({ id: userId }, String(process.env.TOKEN_SECRET), {
|
||||
expiresIn: String(process.env.TOKEN_EXPIRATION || '15m'),
|
||||
});
|
||||
export const generateToken = (
|
||||
id: string,
|
||||
otherProperties?: { [key: string]: any }
|
||||
) => {
|
||||
return jwt.sign(
|
||||
{ id, ...otherProperties },
|
||||
String(process.env.TOKEN_SECRET),
|
||||
{
|
||||
expiresIn: String(process.env.TOKEN_EXPIRATION || '15m'),
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const generateRefreshToken = (userId: string) => {
|
||||
return jwt.sign({ id: userId }, String(process.env.TOKEN_SECRET), {
|
||||
expiresIn: String(process.env.TOKEN_REFRESH_EXPIRATION || '90d'),
|
||||
});
|
||||
export const generateRefreshToken = (
|
||||
id: string,
|
||||
otherProperties?: { [key: string]: any }
|
||||
) => {
|
||||
return jwt.sign(
|
||||
{ id, ...otherProperties },
|
||||
String(process.env.TOKEN_SECRET),
|
||||
{
|
||||
expiresIn: String(process.env.TOKEN_REFRESH_EXPIRATION || '90d'),
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const authenticateUser = async (
|
||||
@@ -55,7 +69,6 @@ passport.use(
|
||||
await prisma.user
|
||||
.findUnique({
|
||||
include: {
|
||||
serverCredentials: true,
|
||||
serverFolderPermissions: true,
|
||||
serverPermissions: true,
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { Prisma, PrismaClient } from '@prisma/client';
|
||||
|
||||
export const prisma = new PrismaClient({ errorFormat: 'minimal' });
|
||||
export const exclude = <T, Key extends keyof T>(
|
||||
@@ -17,7 +17,7 @@ function sleep(ms: number) {
|
||||
}
|
||||
|
||||
prisma.$use(async (params, next) => {
|
||||
const maxRetries = 5;
|
||||
const maxRetries = 3;
|
||||
let retries = 0;
|
||||
|
||||
do {
|
||||
@@ -25,8 +25,29 @@ prisma.$use(async (params, next) => {
|
||||
const result = await next(params);
|
||||
return result;
|
||||
} catch (err) {
|
||||
console.log('err', err);
|
||||
if (err instanceof Prisma.PrismaClientKnownRequestError) {
|
||||
if (err.code === 'P2002') {
|
||||
retries = 3; // Don't retry on unique constraint violation
|
||||
return null;
|
||||
}
|
||||
}
|
||||
retries += 1;
|
||||
return sleep(500);
|
||||
return sleep(100);
|
||||
}
|
||||
} while (retries < maxRetries);
|
||||
});
|
||||
|
||||
// prisma.$use(async (params, next) => {
|
||||
// const before = Date.now();
|
||||
|
||||
// const result = await next(params);
|
||||
|
||||
// const after = Date.now();
|
||||
|
||||
// console.log(
|
||||
// `Query ${params.model}.${params.action} took ${after - before}ms`
|
||||
// );
|
||||
|
||||
// return result;
|
||||
// });
|
||||
|
||||
Reference in New Issue
Block a user