Merge branch 'main' of https://github.com/marcopedone/infoalloggi-monorepo
This commit is contained in:
commit
d35951657a
2 changed files with 26 additions and 36 deletions
|
|
@ -152,39 +152,29 @@ export const logIn = async ({
|
||||||
const accessToken = await signToken(payload, "1h", "accessToken");
|
const accessToken = await signToken(payload, "1h", "accessToken");
|
||||||
const refreshToken = await signToken(payload, "1d", "refreshToken");
|
const refreshToken = await signToken(payload, "1d", "refreshToken");
|
||||||
|
|
||||||
// Send Access Token in Cookie
|
try {
|
||||||
await setCookie(ACCESS_TOKEN_COOKIE_NAME, accessToken, {
|
await setCookie(ACCESS_TOKEN_COOKIE_NAME, accessToken, {
|
||||||
...accessTokenCookieOptions,
|
...accessTokenCookieOptions,
|
||||||
req,
|
req,
|
||||||
res,
|
res,
|
||||||
});
|
});
|
||||||
await setCookie(REFRESH_TOKEN_COOKIE_NAME, refreshToken, {
|
await setCookie(REFRESH_TOKEN_COOKIE_NAME, refreshToken, {
|
||||||
...refreshTokenCookieOptions,
|
...refreshTokenCookieOptions,
|
||||||
req,
|
req,
|
||||||
res,
|
res,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return { status: "success" as const };
|
||||||
|
} catch (cookieError) {
|
||||||
|
console.error("Error setting cookies:", cookieError);
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
|
message: `Errore durante l'impostazione dei cookies: ${(cookieError as Error).message}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const cookies = await getCookies({ req, res });
|
|
||||||
if (!cookies) {
|
|
||||||
throw new TRPCError({
|
|
||||||
code: "INTERNAL_SERVER_ERROR",
|
|
||||||
message: "Errore durante il login, cookies non impostati",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (!cookies[ACCESS_TOKEN_COOKIE_NAME]) {
|
|
||||||
throw new TRPCError({
|
|
||||||
code: "INTERNAL_SERVER_ERROR",
|
|
||||||
message: "Errore durante il login, access token non impostato",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (!cookies[REFRESH_TOKEN_COOKIE_NAME]) {
|
|
||||||
throw new TRPCError({
|
|
||||||
code: "INTERNAL_SERVER_ERROR",
|
|
||||||
message: "Errore durante il login, refresh token non impostato",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return { status: "success" as const };
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.error("Login error:", e);
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "INTERNAL_SERVER_ERROR",
|
code: "INTERNAL_SERVER_ERROR",
|
||||||
message: `Errore login: ${(e as Error).message}`,
|
message: `Errore login: ${(e as Error).message}`,
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,10 @@ import type PublicSchema from "~/schemas/public/PublicSchema";
|
||||||
* The database connection pool.
|
* The database connection pool.
|
||||||
*/
|
*/
|
||||||
const pool = new Pool({
|
const pool = new Pool({
|
||||||
connectionTimeoutMillis: 2000,
|
//connectionTimeoutMillis: 2000,
|
||||||
database: env.POSTGRES_DB,
|
database: env.POSTGRES_DB,
|
||||||
host: env.PGHOST,
|
host: env.PGHOST,
|
||||||
idleTimeoutMillis: 30000,
|
//idleTimeoutMillis: 30000,
|
||||||
max: 10,
|
max: 10,
|
||||||
password: env.POSTGRES_PASSWORD,
|
password: env.POSTGRES_PASSWORD,
|
||||||
port: Number.parseInt(env.PGPORT),
|
port: Number.parseInt(env.PGPORT),
|
||||||
|
|
@ -39,8 +39,8 @@ export const db = new Kysely<Database>({
|
||||||
pool: pool,
|
pool: pool,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
log: (_event) => {
|
log: (event) => {
|
||||||
//DbLogger(event);
|
DbLogger(event);
|
||||||
},
|
},
|
||||||
|
|
||||||
//plugins: [new SerializePlugin()]
|
//plugins: [new SerializePlugin()]
|
||||||
|
|
@ -53,7 +53,7 @@ export const db = new Kysely<Database>({
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
const _DbLogger = (event: LogEvent) => {
|
const DbLogger = (event: LogEvent) => {
|
||||||
if (event.level === "query") {
|
if (event.level === "query") {
|
||||||
console.log("\x1b[33mquery:\x1b[0m", event.query.sql);
|
console.log("\x1b[33mquery:\x1b[0m", event.query.sql);
|
||||||
console.log("\x1b[36mparams:\x1b[0m", event.query.parameters);
|
console.log("\x1b[36mparams:\x1b[0m", event.query.parameters);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue