Skip to content

Commit d59e0e1

Browse files
committed
refactor: lighter middleware
1 parent 5f50f46 commit d59e0e1

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

apps/website/src/components/common/NavGate.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { PropsWithChildren } from 'react';
55
import { createContext, useContext, useEffect, useMemo } from 'react';
66
import { Skeleton } from './Skeleton';
77
import { client } from '@/data/client';
8+
import { URLS } from '@/utils/urls';
89

910
interface NavGateContextValue {
1011
readonly isAuthenticated: boolean;
@@ -28,7 +29,7 @@ export function NavGateProvider({ children }: PropsWithChildren) {
2829

2930
useEffect(() => {
3031
if (!isLoading && user === null) {
31-
router.replace('/login');
32+
router.push(URLS.API.LOGIN);
3233
}
3334
}, [isLoading, user, router]);
3435

apps/website/src/middleware.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
// TODO: Guild level auth methinks
2-
// TODO: 5xx?
31
import { NextResponse } from 'next/server';
42
import type { NextRequest } from 'next/server';
5-
import { server } from '@/data/server';
6-
import { URLS } from '@/utils/urls';
3+
import { URLS } from './utils/urls';
74

85
export async function middleware(request: NextRequest) {
9-
const user = await server.auth.me.fetch();
6+
const cookies = request.cookies;
107

11-
if (!user.data) {
8+
if (!cookies.has('refresh_token')) {
129
return NextResponse.redirect(new URL(URLS.API.LOGIN, request.url));
1310
}
1411

packages/private/backend-core/src/lib/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import z from 'zod';
44

55
const envSchema = z.object({
66
// General
7-
IS_PRODUCTION: z.coerce.boolean().default(false),
7+
IS_PRODUCTION: z.stringbool().default(false),
88
ROOT_DOMAIN: z.string(),
99
ADMINS: z
1010
.string()

0 commit comments

Comments
 (0)