feat: allow to disable auth during development (#21)

This commit is contained in:
Dominic Elm
2024-07-30 10:31:35 +02:00
committed by GitHub
parent 4df1da4908
commit 58af0dea8c
6 changed files with 11 additions and 20 deletions

View File

@@ -1,12 +1,5 @@
import { env } from 'node:process';
import { isAuthenticated } from './sessions';
import { json, redirect, type LoaderFunctionArgs } from '@remix-run/cloudflare';
export function verifyPassword(password: string, cloudflareEnv: Env) {
const loginPassword = env.LOGIN_PASSWORD || cloudflareEnv.LOGIN_PASSWORD;
return password === loginPassword;
}
import { isAuthenticated } from './sessions';
type RequestArgs = Pick<LoaderFunctionArgs, 'request' | 'context'>;
@@ -14,7 +7,7 @@ export async function handleAuthRequest<T extends RequestArgs>(args: T, body: ob
const { request, context } = args;
const { authenticated, response } = await isAuthenticated(request, context.cloudflare.env);
if (authenticated) {
if (authenticated || import.meta.env.VITE_DISABLE_AUTH) {
return json(body, response);
}
@@ -25,7 +18,7 @@ export async function handleWithAuth<T extends RequestArgs>(args: T, handler: (a
const { request, context } = args;
const { authenticated, response } = await isAuthenticated(request, context.cloudflare.env);
if (authenticated) {
if (authenticated || import.meta.env.VITE_DISABLE_AUTH) {
const handlerResponse = await handler(args);
if (response) {