Update to authorize local ipv4 ip addresses
edit way to work in local try false in secure add log fix, update funct isRunningLoccaly fix fmt refacto
This commit is contained in:
28
lib/auth.ts
28
lib/auth.ts
@@ -50,6 +50,13 @@ async function verifyAuthJwt(key: CryptoKey, jwt: string) {
|
||||
throw new Error('Invalid JWT');
|
||||
}
|
||||
|
||||
function resolveCookieDomain(request: Request) {
|
||||
if (!isBaseUrlAnIp() || isRunningLocally(request)) {
|
||||
return baseUrl.replace('https://', '').replace('http://', '').split(':')[0];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
export async function getDataFromRequest(request: Request) {
|
||||
const cookies = getCookies(request.headers);
|
||||
const authorizationHeader = request.headers.get('authorization');
|
||||
@@ -158,14 +165,9 @@ export async function logoutUser(request: Request) {
|
||||
secure: isRunningLocally(request) ? false : true,
|
||||
httpOnly: true,
|
||||
sameSite: 'Lax',
|
||||
domain: resolveCookieDomain(request),
|
||||
};
|
||||
|
||||
if (!isBaseUrlAnIp()) {
|
||||
cookie.domain = isRunningLocally(request)
|
||||
? 'localhost'
|
||||
: baseUrl.replace('https://', '').replace('http://', '').split(':')[0];
|
||||
}
|
||||
|
||||
const response = new Response('Logged Out', {
|
||||
status: 303,
|
||||
headers: { 'Location': '/', 'Content-Type': 'text/html; charset=utf-8' },
|
||||
@@ -212,14 +214,9 @@ export async function createSessionCookie(
|
||||
secure: isRunningLocally(request) ? false : true,
|
||||
httpOnly: true,
|
||||
sameSite: 'Lax',
|
||||
domain: resolveCookieDomain(request),
|
||||
};
|
||||
|
||||
if (!isBaseUrlAnIp()) {
|
||||
cookie.domain = isRunningLocally(request)
|
||||
? 'localhost'
|
||||
: baseUrl.replace('https://', '').replace('http://', '').split(':')[0];
|
||||
}
|
||||
|
||||
setCookie(response.headers, cookie);
|
||||
|
||||
return response;
|
||||
@@ -241,14 +238,9 @@ export async function updateSessionCookie(
|
||||
secure: isRunningLocally(request) ? false : true,
|
||||
httpOnly: true,
|
||||
sameSite: 'Lax',
|
||||
domain: resolveCookieDomain(request),
|
||||
};
|
||||
|
||||
if (!isBaseUrlAnIp()) {
|
||||
cookie.domain = isRunningLocally(request)
|
||||
? 'localhost'
|
||||
: baseUrl.replace('https://', '').replace('http://', '').split(':')[0];
|
||||
}
|
||||
|
||||
setCookie(response.headers, cookie);
|
||||
|
||||
return response;
|
||||
|
||||
Reference in New Issue
Block a user