feat: allow to disable auth during development (#21)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { createCookieSessionStorage, redirect } from '@remix-run/cloudflare';
|
||||
import { decodeJwt } from 'jose';
|
||||
import { request as doRequest } from '~/lib/fetch';
|
||||
import { CLIENT_ID, CLIENT_ORIGIN } from '~/lib/constants';
|
||||
import { request as doRequest } from '~/lib/fetch';
|
||||
import { logger } from '~/utils/logger';
|
||||
|
||||
const DEV_SESSION_SECRET = import.meta.env.DEV ? 'LZQMrERo3Ewn/AbpSYJ9aw==' : undefined;
|
||||
@@ -33,7 +33,7 @@ export async function isAuthenticated(request: Request, env: Env) {
|
||||
try {
|
||||
data = await refreshToken(token);
|
||||
} catch {
|
||||
// ignore
|
||||
// we can ignore the error here because it's handled below
|
||||
}
|
||||
|
||||
if (data != null) {
|
||||
|
||||
Reference in New Issue
Block a user