chore:little fixes and formating and linting and patches
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { parseCookieDomain } from './parse-cookie-domain';
|
||||
|
||||
const parsed = parseCookieDomain(
|
||||
(process.env.DASHBOARD_URL || process.env.NEXT_PUBLIC_DASHBOARD_URL) ?? '',
|
||||
(process.env.DASHBOARD_URL || process.env.NEXT_PUBLIC_DASHBOARD_URL) ?? ''
|
||||
);
|
||||
|
||||
export const COOKIE_MAX_AGE = 60 * 60 * 24 * 30;
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
export * from './src';
|
||||
export * from './constants';
|
||||
export * from './src';
|
||||
|
||||
@@ -24,4 +24,4 @@
|
||||
"peerDependencies": {
|
||||
"react": "catalog:"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
||||
import { parseCookieDomain } from './parse-cookie-domain';
|
||||
|
||||
describe('parseCookieDomain', () => {
|
||||
@@ -223,7 +223,7 @@ describe('parseCookieDomain', () => {
|
||||
|
||||
it('should handle domains with all URL components', () => {
|
||||
expect(
|
||||
parseCookieDomain('https://example.com:8080/path?param=value#fragment'),
|
||||
parseCookieDomain('https://example.com:8080/path?param=value#fragment')
|
||||
).toEqual({
|
||||
domain: '.example.com',
|
||||
secure: true,
|
||||
@@ -274,7 +274,7 @@ describe('parseCookieDomain', () => {
|
||||
|
||||
it('should throw error for URLs with invalid characters', () => {
|
||||
expect(() =>
|
||||
parseCookieDomain('http://example.com:invalid-port'),
|
||||
parseCookieDomain('http://example.com:invalid-port')
|
||||
).toThrow();
|
||||
});
|
||||
});
|
||||
@@ -296,7 +296,7 @@ describe('parseCookieDomain', () => {
|
||||
|
||||
it('should handle subdomains of openpanel.dev correctly', () => {
|
||||
expect(
|
||||
parseCookieDomain('https://staging.dashboard.openpanel.dev'),
|
||||
parseCookieDomain('https://staging.dashboard.openpanel.dev')
|
||||
).toEqual({
|
||||
domain: '.openpanel.dev',
|
||||
secure: true,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { encodeHexLowerCase } from '@oslojs/encoding';
|
||||
|
||||
export async function hashPassword(password: string): Promise<string> {
|
||||
return await hash(password, {
|
||||
memoryCost: 19456,
|
||||
memoryCost: 19_456,
|
||||
timeCost: 2,
|
||||
outputLen: 32,
|
||||
parallelism: 1,
|
||||
@@ -13,13 +13,13 @@ export async function hashPassword(password: string): Promise<string> {
|
||||
|
||||
export async function verifyPasswordHash(
|
||||
hash: string,
|
||||
password: string,
|
||||
password: string
|
||||
): Promise<boolean> {
|
||||
return await verify(hash, password);
|
||||
}
|
||||
|
||||
export async function verifyPasswordStrength(
|
||||
password: string,
|
||||
password: string
|
||||
): Promise<boolean> {
|
||||
if (password.length < 8 || password.length > 255) {
|
||||
return false;
|
||||
@@ -27,7 +27,7 @@ export async function verifyPasswordStrength(
|
||||
const hash = encodeHexLowerCase(sha1(new TextEncoder().encode(password)));
|
||||
const hashPrefix = hash.slice(0, 5);
|
||||
const response = await fetch(
|
||||
`https://api.pwnedpasswords.com/range/${hashPrefix}`,
|
||||
`https://api.pwnedpasswords.com/range/${hashPrefix}`
|
||||
);
|
||||
const data = await response.text();
|
||||
const items = data.split('\n');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import crypto from 'node:crypto';
|
||||
import { type Session, type User, db } from '@openpanel/db';
|
||||
import { db, type Session, type User } from '@openpanel/db';
|
||||
import { sha256 } from '@oslojs/crypto/sha2';
|
||||
import {
|
||||
encodeBase32LowerCaseNoPadding,
|
||||
@@ -15,7 +15,7 @@ export function generateSessionToken(): string {
|
||||
|
||||
export async function createSession(
|
||||
token: string,
|
||||
userId: string,
|
||||
userId: string
|
||||
): Promise<Session> {
|
||||
const sessionId = encodeHexLowerCase(sha256(new TextEncoder().encode(token)));
|
||||
const session: Session = {
|
||||
@@ -38,7 +38,7 @@ export const EMPTY_SESSION: SessionValidationResult = {
|
||||
};
|
||||
|
||||
export async function createDemoSession(
|
||||
userId: string,
|
||||
userId: string
|
||||
): Promise<SessionValidationResult> {
|
||||
const user = await db.user.findUniqueOrThrow({
|
||||
where: {
|
||||
@@ -66,7 +66,7 @@ export const decodeSessionToken = (token: string): string | null => {
|
||||
};
|
||||
|
||||
export async function validateSessionToken(
|
||||
token: string | null | undefined,
|
||||
token: string | null | undefined
|
||||
): Promise<SessionValidationResult> {
|
||||
if (process.env.DEMO_USER_ID) {
|
||||
return createDemoSession(process.env.DEMO_USER_ID);
|
||||
|
||||
Reference in New Issue
Block a user