Skip to content

Commit

Permalink
Merge remote changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CHRISCARLON committed Nov 17, 2024
2 parents be8c84e + 3e4e5d4 commit f2d49d5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
4 changes: 0 additions & 4 deletions gridwalk-ui/src/app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
"use client";
import React from "react";
import LoginForm from "./components/loginForm";
import GridBackground from "./components/gridBackground";
Expand All @@ -8,16 +7,13 @@ export default function LoginPage(): JSX.Element {
return (
<>
<title>Sign In | GridWalk</title>

{/* Animated Background */}
<GridBackground />

{/* Content */}
<div className="relative grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family:var(--font-geist-sans)]">
<header className="w-full max-w-md text-center row-start-1">
<Logo />
</header>

<main className="flex flex-col gap-8 row-start-2 items-center w-full max-w-md">
<LoginForm />
</main>
Expand Down
47 changes: 47 additions & 0 deletions gridwalk-ui/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// middleware.ts
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'

export async function middleware(request: NextRequest) {
// Only run this middleware for the login page
if (request.nextUrl.pathname === '/login') {
const sessionId = request.cookies.get('sid')

// If no session cookie exists, allow access to login page
if (!sessionId) {
return NextResponse.next()
}

try {
const apiHost = process.env.GRIDWALK_API
if (!apiHost) {
throw new Error('GRIDWALK_API environment variable is not set')
}

const response = await fetch(`${apiHost}/profile`, {
headers: {
'Authorization': `Bearer ${sessionId.value}`
}
})

// If authenticated, redirect to workspace
if (response.ok) {
return NextResponse.redirect(new URL('/workspace', request.url))
}

// If not authenticated, allow access to login page
return NextResponse.next()

} catch (error) {
console.error('Error checking auth status:', error)
return NextResponse.next()
}
}

return NextResponse.next()
}

// Configure the middleware to only run on the login page
export const config = {
matcher: '/login'
}

0 comments on commit f2d49d5

Please sign in to comment.