Add Better Auth admin authentication
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
"use server";
|
||||
|
||||
import { cookies } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import {
|
||||
createClearedMockSessionCookie,
|
||||
createMockSessionCookie,
|
||||
} from "@/lib/mock-auth";
|
||||
|
||||
export async function signInMock() {
|
||||
const cookieStore = await cookies();
|
||||
|
||||
cookieStore.set(createMockSessionCookie());
|
||||
redirect("/dashboard");
|
||||
}
|
||||
|
||||
export async function signUpMock() {
|
||||
const cookieStore = await cookies();
|
||||
|
||||
cookieStore.set(createMockSessionCookie());
|
||||
redirect("/dashboard");
|
||||
}
|
||||
|
||||
export async function signOutMock() {
|
||||
const cookieStore = await cookies();
|
||||
|
||||
cookieStore.set(createClearedMockSessionCookie());
|
||||
redirect("/");
|
||||
}
|
||||
3
app/api/auth/[...all]/route.ts
Normal file
3
app/api/auth/[...all]/route.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { handler } from "@/lib/auth-server";
|
||||
|
||||
export const { GET, POST } = handler;
|
||||
@@ -1,7 +1,7 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { isAuthenticated } from "@/lib/auth-server";
|
||||
import { DashboardSidebar } from "@/components/dashboard-sidebar";
|
||||
import { getCurrentMockSession } from "@/lib/mock-session";
|
||||
import { getDashboardRedirectPath } from "@/lib/route-guards";
|
||||
|
||||
export default async function DashboardLayout({
|
||||
@@ -9,16 +9,16 @@ export default async function DashboardLayout({
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const session = await getCurrentMockSession();
|
||||
const redirectPath = getDashboardRedirectPath(session);
|
||||
const hasSession = await isAuthenticated();
|
||||
const redirectPath = getDashboardRedirectPath(hasSession);
|
||||
|
||||
if (redirectPath || !session) {
|
||||
if (redirectPath) {
|
||||
redirect(redirectPath ?? "/");
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-dvh bg-background md:flex">
|
||||
<DashboardSidebar session={session} />
|
||||
<DashboardSidebar />
|
||||
<div className="min-w-0 flex-1">{children}</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import { ConvexClientProvider } from "@/components/convex-client-provider";
|
||||
import { getToken } from "@/lib/auth-server";
|
||||
import "./globals.css";
|
||||
|
||||
const geistSans = Geist({
|
||||
@@ -18,18 +19,20 @@ export const metadata: Metadata = {
|
||||
description: "Interner Akquise-Agent fuer lokale Webdesign-Leads",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
export default async function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
const token = await getToken();
|
||||
|
||||
return (
|
||||
<html
|
||||
lang="de"
|
||||
className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`}
|
||||
>
|
||||
<body className="min-h-full flex flex-col">
|
||||
<ConvexClientProvider>{children}</ConvexClientProvider>
|
||||
<ConvexClientProvider initialToken={token}>{children}</ConvexClientProvider>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { AuthEntry } from "@/components/auth-entry";
|
||||
import { getCurrentMockSession } from "@/lib/mock-session";
|
||||
import { isAuthenticated } from "@/lib/auth-server";
|
||||
|
||||
export default async function LoginPage() {
|
||||
const session = await getCurrentMockSession();
|
||||
const isSessionActive = await isAuthenticated();
|
||||
|
||||
if (session) {
|
||||
if (isSessionActive) {
|
||||
redirect("/dashboard");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
import { AuthEntry } from "@/components/auth-entry";
|
||||
import { getCurrentMockSession } from "@/lib/mock-session";
|
||||
import { isAuthenticated } from "@/lib/auth-server";
|
||||
|
||||
export default async function Home() {
|
||||
const session = await getCurrentMockSession();
|
||||
const isSessionActive = await isAuthenticated();
|
||||
|
||||
if (session) {
|
||||
if (isSessionActive) {
|
||||
redirect("/dashboard");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user