style: clean up code formatting and remove trailing whitespace
refactor: reorganize imports and fix type imports
This commit is contained in:
1 parent
d3704602fd
commit
47c04de6fe
232 files changed
+7140
-4798
No files matched your search
+5
-6
@@ -31,7 +31,7 @@ function getJWTRefreshSecret(): string {
|
||||
const secret = process.env.JWT_REFRESH_SECRET;
|
||||
if (!secret) {
|
||||
throw new Error(
|
||||
"JWT_REFRESH_SECRET não está definido nas variáveis de ambiente"
|
||||
"JWT_REFRESH_SECRET não está definido nas variáveis de ambiente",
|
||||
);
|
||||
}
|
||||
return secret;
|
||||
@@ -55,7 +55,7 @@ interface TokenOptions {
|
||||
export function generateAccessToken(
|
||||
userId: number,
|
||||
username: string,
|
||||
options?: TokenOptions
|
||||
options?: TokenOptions,
|
||||
): string {
|
||||
const payload: TokenPayload = {
|
||||
userId,
|
||||
@@ -79,7 +79,7 @@ export function generateAccessToken(
|
||||
export function generateRefreshToken(
|
||||
userId: number,
|
||||
username: string,
|
||||
options?: TokenOptions
|
||||
options?: TokenOptions,
|
||||
): string {
|
||||
const payload: TokenPayload = {
|
||||
userId,
|
||||
@@ -118,7 +118,7 @@ export function verifyAccessToken(token: string): {
|
||||
tierSlug: decoded.tierSlug,
|
||||
tierLevel: decoded.tierLevel,
|
||||
};
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -147,8 +147,7 @@ export function verifyRefreshToken(token: string): {
|
||||
tierSlug: decoded.tierSlug,
|
||||
tierLevel: decoded.tierLevel,
|
||||
};
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+20
-14
@@ -3,10 +3,10 @@
|
||||
* Extrai e valida tokens JWT das requisições
|
||||
*/
|
||||
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { cookies } from "next/headers";
|
||||
import { verifyAccessToken } from "./jwt";
|
||||
import { type NextRequest, NextResponse } from "next/server";
|
||||
import { getSession } from "@/lib/redis/session";
|
||||
import { verifyAccessToken } from "./jwt";
|
||||
|
||||
export interface AuthenticatedUser {
|
||||
userId: number;
|
||||
@@ -48,8 +48,10 @@ function toAuthenticatedUser(payload: {
|
||||
}
|
||||
|
||||
export async function requireAuth(
|
||||
request: NextRequest
|
||||
): Promise<AuthenticatedUser | NextResponse<{ success: false; error: string }>> {
|
||||
request: NextRequest,
|
||||
): Promise<
|
||||
AuthenticatedUser | NextResponse<{ success: false; error: string }>
|
||||
> {
|
||||
// Tentar primeiro com Bearer token
|
||||
const token = extractToken(request);
|
||||
|
||||
@@ -77,7 +79,7 @@ export async function requireAuth(
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
// Se der erro ao acessar cookies, continuar com o erro de token
|
||||
}
|
||||
|
||||
@@ -86,7 +88,7 @@ export async function requireAuth(
|
||||
success: false,
|
||||
error: "Token de autenticação não fornecido ou inválido",
|
||||
},
|
||||
{ status: 401 }
|
||||
{ status: 401 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -98,7 +100,7 @@ export async function requireAuth(
|
||||
* @returns Dados do usuário ou null
|
||||
*/
|
||||
export async function optionalAuth(
|
||||
request: NextRequest
|
||||
request: NextRequest,
|
||||
): Promise<AuthenticatedUser | null> {
|
||||
// Tentar primeiro com Bearer token
|
||||
const token = extractToken(request);
|
||||
@@ -125,7 +127,7 @@ export async function optionalAuth(
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (_error) {
|
||||
// Ignorar erros de cookie
|
||||
}
|
||||
|
||||
@@ -133,8 +135,10 @@ export async function optionalAuth(
|
||||
}
|
||||
|
||||
export async function requireAdminUser(
|
||||
request: NextRequest
|
||||
): Promise<AuthenticatedUser | NextResponse<{ success: false; error: string }>> {
|
||||
request: NextRequest,
|
||||
): Promise<
|
||||
AuthenticatedUser | NextResponse<{ success: false; error: string }>
|
||||
> {
|
||||
const auth = await requireAuth(request);
|
||||
|
||||
if (auth instanceof NextResponse) {
|
||||
@@ -147,7 +151,7 @@ export async function requireAdminUser(
|
||||
success: false,
|
||||
error: "Acesso restrito ao administrador.",
|
||||
},
|
||||
{ status: 403 }
|
||||
{ status: 403 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -156,8 +160,10 @@ export async function requireAdminUser(
|
||||
|
||||
export async function requireTierLevel(
|
||||
request: NextRequest,
|
||||
minimumLevel: number
|
||||
): Promise<AuthenticatedUser | NextResponse<{ success: false; error: string }>> {
|
||||
minimumLevel: number,
|
||||
): Promise<
|
||||
AuthenticatedUser | NextResponse<{ success: false; error: string }>
|
||||
> {
|
||||
const auth = await requireAuth(request);
|
||||
|
||||
if (auth instanceof NextResponse) {
|
||||
@@ -172,7 +178,7 @@ export async function requireTierLevel(
|
||||
success: false,
|
||||
error: "Plano atual não possui acesso a este recurso.",
|
||||
},
|
||||
{ status: 403 }
|
||||
{ status: 403 },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ export async function hashPassword(password: string): Promise<string> {
|
||||
*/
|
||||
export async function comparePassword(
|
||||
password: string,
|
||||
hash: string
|
||||
hash: string,
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
const match = await bcrypt.compare(password, hash);
|
||||
@@ -40,4 +40,3 @@ export async function comparePassword(
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user