Skip to content

Commit

Permalink
Fixed auth check.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Jan 31, 2025
1 parent 85382e2 commit aaf8b19
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 0 additions & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
2 changes: 1 addition & 1 deletion src/lib/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function decodeHeader(s: string | undefined | null): string | undefined | null {
return Buffer.from(s, 'latin1').toString('utf-8');
}

export async function getLocation(ip: string, headers: Headers) {
export async function getLocation(ip: string = '', headers: Headers) {
// Ignore local ips
if (await isLocalhost(ip)) {
return;
Expand Down
9 changes: 6 additions & 3 deletions src/lib/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export async function parseRequest(
let query = Object.fromEntries(url.searchParams);
let body = await getJsonBody(request);
let error: () => void | undefined;
let auth = null;

if (schema) {
const isGet = request.method === 'GET';
Expand All @@ -36,10 +37,12 @@ export async function parseRequest(
}
}

const auth = !error && !options?.skipAuth ? await checkAuth(request) : null;
if (!options?.skipAuth && !error) {
auth = await checkAuth(request);

if (!error && !auth) {
error = () => unauthorized();
if (!auth) {
error = () => unauthorized();
}
}

return { url, query, body, auth, error };
Expand Down

0 comments on commit aaf8b19

Please sign in to comment.