added explicit route
This commit is contained in:
parent
561af1adf2
commit
6e2817ef73
5 changed files with 61 additions and 10 deletions
|
|
@ -16,6 +16,9 @@ FROM node:20.18.0-slim
|
||||||
|
|
||||||
WORKDIR /home/perplexica
|
WORKDIR /home/perplexica
|
||||||
|
|
||||||
|
# 🐧 Install curl + netstat (from net-tools)
|
||||||
|
RUN apt-get update && apt-get install -y curl net-tools && apt-get clean
|
||||||
|
|
||||||
COPY --from=builder /home/perplexica/public ./public
|
COPY --from=builder /home/perplexica/public ./public
|
||||||
COPY --from=builder /home/perplexica/.next/static ./public/_next/static
|
COPY --from=builder /home/perplexica/.next/static ./public/_next/static
|
||||||
|
|
||||||
|
|
|
||||||
4
src/app/[auth0]/route.ts
Normal file
4
src/app/[auth0]/route.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
import { handleAuth } from '@auth0/nextjs-auth0';
|
||||||
|
|
||||||
|
export const GET = handleAuth();
|
||||||
|
export const POST = handleAuth();
|
||||||
|
|
@ -3,6 +3,7 @@ import { Message } from './ChatWindow';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { formatTimeDifference } from '@/lib/utils';
|
import { formatTimeDifference } from '@/lib/utils';
|
||||||
import DeleteChat from './DeleteChat';
|
import DeleteChat from './DeleteChat';
|
||||||
|
import ProfileButton from './ProfileButton'; // adjust path if needed
|
||||||
|
|
||||||
const Navbar = ({
|
const Navbar = ({
|
||||||
chatId,
|
chatId,
|
||||||
|
|
@ -64,6 +65,7 @@ const Navbar = ({
|
||||||
className="active:scale-95 transition duration-100 cursor-pointer"
|
className="active:scale-95 transition duration-100 cursor-pointer"
|
||||||
/>
|
/>
|
||||||
<DeleteChat redirect chatId={chatId} chats={[]} setChats={() => {}} />
|
<DeleteChat redirect chatId={chatId} chats={[]} setChats={() => {}} />
|
||||||
|
<ProfileButton /> {/* 👈 Add this here */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
32
src/components/ProfileButton.tsx
Normal file
32
src/components/ProfileButton.tsx
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
interface UserProfile {
|
||||||
|
name?: string;
|
||||||
|
email?: string;
|
||||||
|
picture?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function ProfileButton() {
|
||||||
|
const [user, setUser] = useState<UserProfile | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetch('/auth/profile')
|
||||||
|
.then((res) => (res.ok ? res.json() : null))
|
||||||
|
.then((data) => setUser(data?.user))
|
||||||
|
.catch(() => setUser(null));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (!user) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<a href="/auth/logout" title="Log out" className="block p-2">
|
||||||
|
<img
|
||||||
|
src={user.picture}
|
||||||
|
alt="profile"
|
||||||
|
className="rounded-full w-8 h-8 border border-white/20"
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -1,19 +1,29 @@
|
||||||
import type { NextRequest } from "next/server"
|
import { auth0 } from './lib/auth0';
|
||||||
|
import { NextResponse } from 'next/server';
|
||||||
|
import type { NextRequest } from 'next/server';
|
||||||
|
|
||||||
import { auth0 } from "./lib/auth0"
|
|
||||||
|
|
||||||
export async function middleware(request: NextRequest) {
|
export async function middleware(request: NextRequest) {
|
||||||
return await auth0.middleware(request)
|
const res = await auth0.getSession(request);
|
||||||
|
|
||||||
|
if (!res) {
|
||||||
|
// not logged in, redirect to Auth0 login
|
||||||
|
return Response.redirect(
|
||||||
|
new URL('/auth/login', request.url),
|
||||||
|
302
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
matcher: [
|
matcher: [
|
||||||
/*
|
/*
|
||||||
* Match all request paths except for the ones starting with:
|
* Match all paths except:
|
||||||
* - _next/static (static files)
|
* - public files (_next, images, icons, etc.)
|
||||||
* - _next/image (image optimization files)
|
* - auth routes like /auth/login and /auth/callback
|
||||||
* - favicon.ico, sitemap.xml, robots.txt (metadata files)
|
|
||||||
*/
|
*/
|
||||||
"/((?!_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
|
'/((?!_next/static|_next/image|favicon.ico|auth/.*).*)',
|
||||||
],
|
],
|
||||||
}
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue