code refactoring, fixed wrong jwt expire time
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit"
|
||||
|
||||
export type LanguageUnion = "english" | "chinese" | "russian" | "italian" | "spanish" | "korean" | "japanese" | "catalan"
|
||||
export type LanguageUnion =
|
||||
| "english"
|
||||
| "chinese"
|
||||
| "russian"
|
||||
| "italian"
|
||||
| "spanish"
|
||||
| "korean"
|
||||
| "japanese"
|
||||
| "catalan"
|
||||
|
||||
export type ThemeUnion = "light" | "dark"
|
||||
|
||||
export interface SettingsState {
|
||||
|
||||
@@ -95,7 +95,7 @@ export function formatGiB(bytes: number) {
|
||||
export const roundMiB = (bytes: number) => `${(bytes / 1_000_000).toFixed(2)} MiB`
|
||||
export const formatSpeedMiB = (val: number) => `${roundMiB(val)}/s`
|
||||
|
||||
export const dateTimeComparatorFunc = (a: string, b: string) => new Date(a).getTime() - new Date(b).getTime()
|
||||
export const datetimeCompareFunc = (a: string, b: string) => new Date(a).getTime() - new Date(b).getTime()
|
||||
|
||||
export function isRPCResponse(object: any): object is RPCResponse<any> {
|
||||
return 'result' in object && 'id' in object
|
||||
|
||||
@@ -24,7 +24,7 @@ import { I18nContext } from '../providers/i18nProvider'
|
||||
import { RPCClientContext } from '../providers/rpcClientProvider'
|
||||
import { RootState } from '../stores/store'
|
||||
import type { RPCResponse, RPCResult } from '../types'
|
||||
import { dateTimeComparatorFunc, isRPCResponse } from '../utils'
|
||||
import { datetimeCompareFunc, isRPCResponse } from '../utils'
|
||||
|
||||
export default function Home() {
|
||||
// redux state
|
||||
@@ -87,7 +87,7 @@ export default function Home() {
|
||||
|
||||
setActiveDownloads((event.result ?? [])
|
||||
.filter(f => !!f.info.url)
|
||||
.sort((a, b) => dateTimeComparatorFunc(
|
||||
.sort((a, b) => datetimeCompareFunc(
|
||||
b.info.created_at,
|
||||
a.info.created_at,
|
||||
)))
|
||||
|
||||
@@ -160,8 +160,10 @@ func Login(ctx *fiber.Ctx) error {
|
||||
return ctx.SendStatus(fiber.StatusBadRequest)
|
||||
}
|
||||
|
||||
expiresAt := time.Now().Add(time.Hour * 24 * 30)
|
||||
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
||||
"expiresAt": time.Now().Add(time.Minute * 30),
|
||||
"expiresAt": expiresAt,
|
||||
})
|
||||
|
||||
tokenString, err := token.SignedString([]byte(os.Getenv("JWT_SECRET")))
|
||||
@@ -173,7 +175,7 @@ func Login(ctx *fiber.Ctx) error {
|
||||
Name: TOKEN_COOKIE_NAME,
|
||||
HTTPOnly: true,
|
||||
Secure: false,
|
||||
Expires: time.Now().Add(time.Hour * 24 * 30), // 30 days
|
||||
Expires: expiresAt, // 30 days
|
||||
Value: tokenString,
|
||||
Path: "/",
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user