mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-12 21:08:46 +00:00
loadenv에서 수명 관련 환경 변수의 값을 미리 밀리초 단위로 변환해놓도록 변경
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
import { SqliteError } from "better-sqlite3";
|
||||
import { and, eq, gt, lte } from "drizzle-orm";
|
||||
import ms from "ms";
|
||||
import env from "$lib/server/loadenv";
|
||||
import db from "./drizzle";
|
||||
import { refreshToken, tokenUpgradeChallenge } from "./schema";
|
||||
|
||||
const expiresIn = ms(env.jwt.refreshExp);
|
||||
const expiresAt = () => new Date(Date.now() + expiresIn);
|
||||
const expiresAt = () => new Date(Date.now() + env.jwt.refreshExp);
|
||||
|
||||
export const registerRefreshToken = async (
|
||||
userId: number,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import ms from "ms";
|
||||
import { building } from "$app/environment";
|
||||
import { env } from "$env/dynamic/private";
|
||||
|
||||
@@ -9,12 +10,12 @@ export default {
|
||||
databaseUrl: env.DATABASE_URL || "local.db",
|
||||
jwt: {
|
||||
secret: env.JWT_SECRET,
|
||||
accessExp: env.JWT_ACCESS_TOKEN_EXPIRES || "5m",
|
||||
refreshExp: env.JWT_REFRESH_TOKEN_EXPIRES || "14d",
|
||||
accessExp: ms(env.JWT_ACCESS_TOKEN_EXPIRES || "5m"),
|
||||
refreshExp: ms(env.JWT_REFRESH_TOKEN_EXPIRES || "14d"),
|
||||
},
|
||||
challenge: {
|
||||
userClientExp: env.USER_CLIENT_CHALLENGE_EXPIRES || "5m",
|
||||
tokenUpgradeExp: env.TOKEN_UPGRADE_CHALLENGE_EXPIRES || "5m",
|
||||
userClientExp: ms(env.USER_CLIENT_CHALLENGE_EXPIRES || "5m"),
|
||||
tokenUpgradeExp: ms(env.TOKEN_UPGRADE_CHALLENGE_EXPIRES || "5m"),
|
||||
},
|
||||
libraryPath: env.LIBRARY_PATH || "library",
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ type Permission = "pendingClient" | "activeClient";
|
||||
|
||||
export const issueToken = (payload: TokenPayload) => {
|
||||
return jwt.sign(payload, env.jwt.secret, {
|
||||
expiresIn: payload.type === "access" ? env.jwt.accessExp : env.jwt.refreshExp,
|
||||
expiresIn: (payload.type === "access" ? env.jwt.accessExp : env.jwt.refreshExp) / 1000,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { error } from "@sveltejs/kit";
|
||||
import argon2 from "argon2";
|
||||
import ms from "ms";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { getClient, getClientByPubKeys, getUserClient } from "$lib/server/db/client";
|
||||
import { getUserByEmail } from "$lib/server/db/user";
|
||||
@@ -86,8 +85,7 @@ export const refreshToken = async (refreshToken: string) => {
|
||||
};
|
||||
};
|
||||
|
||||
const expiresIn = ms(env.challenge.tokenUpgradeExp);
|
||||
const expiresAt = () => new Date(Date.now() + expiresIn);
|
||||
const expiresAt = () => new Date(Date.now() + env.challenge.tokenUpgradeExp);
|
||||
|
||||
const createChallenge = async (
|
||||
ip: string,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { error } from "@sveltejs/kit";
|
||||
import ms from "ms";
|
||||
import {
|
||||
createClient,
|
||||
getClient,
|
||||
@@ -27,8 +26,7 @@ export const getUserClientList = async (userId: number) => {
|
||||
};
|
||||
};
|
||||
|
||||
const expiresIn = ms(env.challenge.userClientExp);
|
||||
const expiresAt = () => new Date(Date.now() + expiresIn);
|
||||
const expiresAt = () => new Date(Date.now() + env.challenge.userClientExp);
|
||||
|
||||
const createUserClientChallenge = async (
|
||||
userId: number,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
import ms from "ms";
|
||||
import env from "$lib/server/loadenv";
|
||||
import { loginRequest } from "$lib/server/schemas";
|
||||
import { login } from "$lib/server/services/auth";
|
||||
@@ -13,12 +12,12 @@ export const POST: RequestHandler = async ({ request, cookies }) => {
|
||||
const { accessToken, refreshToken } = await login(email, password);
|
||||
cookies.set("accessToken", accessToken, {
|
||||
path: "/",
|
||||
maxAge: Math.floor(ms(env.jwt.accessExp) / 1000),
|
||||
maxAge: env.jwt.accessExp / 1000,
|
||||
sameSite: "strict",
|
||||
});
|
||||
cookies.set("refreshToken", refreshToken, {
|
||||
path: "/api/auth",
|
||||
maxAge: Math.floor(ms(env.jwt.refreshExp) / 1000),
|
||||
maxAge: env.jwt.refreshExp / 1000,
|
||||
sameSite: "strict",
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
import ms from "ms";
|
||||
import env from "$lib/server/loadenv";
|
||||
import { refreshToken as doRefreshToken } from "$lib/server/services/auth";
|
||||
import type { RequestHandler } from "./$types";
|
||||
@@ -11,12 +10,12 @@ export const POST: RequestHandler = async ({ cookies }) => {
|
||||
const { accessToken, refreshToken } = await doRefreshToken(token);
|
||||
cookies.set("accessToken", accessToken, {
|
||||
path: "/",
|
||||
maxAge: ms(env.jwt.accessExp) / 1000,
|
||||
maxAge: env.jwt.accessExp / 1000,
|
||||
sameSite: "strict",
|
||||
});
|
||||
cookies.set("refreshToken", refreshToken, {
|
||||
path: "/api/auth",
|
||||
maxAge: ms(env.jwt.refreshExp) / 1000,
|
||||
maxAge: env.jwt.refreshExp / 1000,
|
||||
sameSite: "strict",
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { error, text } from "@sveltejs/kit";
|
||||
import ms from "ms";
|
||||
import env from "$lib/server/loadenv";
|
||||
import { tokenUpgradeVerifyRequest } from "$lib/server/schemas";
|
||||
import { upgradeToken } from "$lib/server/services/auth";
|
||||
@@ -21,12 +20,12 @@ export const POST: RequestHandler = async ({ request, cookies, getClientAddress
|
||||
);
|
||||
cookies.set("accessToken", accessToken, {
|
||||
path: "/",
|
||||
maxAge: ms(env.jwt.accessExp) / 1000,
|
||||
maxAge: env.jwt.accessExp / 1000,
|
||||
sameSite: "strict",
|
||||
});
|
||||
cookies.set("refreshToken", refreshToken, {
|
||||
path: "/api/auth",
|
||||
maxAge: ms(env.jwt.refreshExp) / 1000,
|
||||
maxAge: env.jwt.refreshExp / 1000,
|
||||
sameSite: "strict",
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user