From 34b1d33ffbba362d18e5b2d3cb7817a1ff8d74cb Mon Sep 17 00:00:00 2001 From: Philipp Traber Date: Fri, 18 Oct 2024 18:28:53 +0200 Subject: [PATCH] add oauth --- Dockerfile | 4 - docker-compose.yml | 4 +- package-lock.json | 156 +++++++++++++++++- package.json | 2 + src/actions/block_actions.ts | 25 ++- src/actions/page_actions.ts | 62 ++++--- src/app/api/auth/[...nextauth]/route.ts | 2 + src/app/globals.css | 70 +++++++- src/app/page.tsx | 12 +- src/app/~/dash/[uuid]/page.tsx | 11 +- src/app/~/dash/layout.tsx | 30 +++- src/app/~/dash/page.tsx | 1 + src/app/~/page.tsx | 24 +++ src/auth.ts | 6 + src/components/CustomPageComponent.tsx | 23 ++- src/components/CustomPageDashboard.tsx | 5 +- src/components/forms/createCustomPageForm.tsx | 5 +- src/components/forms/createLinkBlockForm.tsx | 10 +- .../forms/createRedirectPageForm.tsx | 7 +- src/components/forms/deleteLinkBlockForm.tsx | 17 +- src/components/forms/deletePageForm.tsx | 16 +- src/components/forms/pinPageToRootForm.tsx | 21 ++- src/components/forms/signInButton.tsx | 15 ++ src/components/forms/signOutButton.tsx | 15 ++ src/middleware.ts | 1 + src/utils.tsx | 15 +- 26 files changed, 468 insertions(+), 91 deletions(-) create mode 100644 src/app/api/auth/[...nextauth]/route.ts create mode 100644 src/app/~/page.tsx create mode 100644 src/auth.ts create mode 100644 src/components/forms/signInButton.tsx create mode 100644 src/components/forms/signOutButton.tsx create mode 100644 src/middleware.ts diff --git a/Dockerfile b/Dockerfile index 84ffe76..fda97af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,10 +22,6 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . -## WORKAROUND: -RUN rm -rf src/app/~/dash -RUN rm -rf src/app/actions - # Next.js collects completely anonymous telemetry data about general usage. # Learn more here: https://nextjs.org/telemetry # Uncomment the following line in case you want to disable telemetry during the build. diff --git a/docker-compose.yml b/docker-compose.yml index 3e238b2..cf74934 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,4 +13,6 @@ services: web: build: . ports: - - 3000:3000 \ No newline at end of file + - 3000:3000 + env_file: + - .env \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 324b178..ba1b1ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,8 @@ "@prisma/client": "^5.18.0", "js-sha256": "^0.11.0", "next": "^15.0.0-canary.195", + "next-auth": "^5.0.0-beta.22", + "react-hot-toast": "^2.4.1", "ua-parser-js": "^1.0.38", "zod": "^3.23.8" }, @@ -40,6 +42,37 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/@auth/core": { + "version": "0.35.3", + "resolved": "https://registry.npmjs.org/@auth/core/-/core-0.35.3.tgz", + "integrity": "sha512-g6qfiqU4OtyvIEZ8J7UoIwAxEnNnLJV0/f/DW41U+4G5nhBlaCrnKhawJIJpU0D3uavXLeDT3B0BkjtiimvMDA==", + "license": "ISC", + "dependencies": { + "@panva/hkdf": "^1.1.1", + "@types/cookie": "0.6.0", + "cookie": "0.6.0", + "jose": "^5.1.3", + "oauth4webapi": "^2.10.4", + "preact": "10.11.3", + "preact-render-to-string": "5.2.3" + }, + "peerDependencies": { + "@simplewebauthn/browser": "^9.0.1", + "@simplewebauthn/server": "^9.0.2", + "nodemailer": "^6.8.0" + }, + "peerDependenciesMeta": { + "@simplewebauthn/browser": { + "optional": true + }, + "@simplewebauthn/server": { + "optional": true + }, + "nodemailer": { + "optional": true + } + } + }, "node_modules/@emnapi/runtime": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.2.0.tgz", @@ -810,6 +843,15 @@ "node": ">=12.4.0" } }, + "node_modules/@panva/hkdf": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@panva/hkdf/-/hkdf-1.2.1.tgz", + "integrity": "sha512-6oclG6Y3PiDFcoyk8srjLfVKyMfVCKJ27JwNPViuXziFpmdz+MZnZN/aKY0JGXgYuO/VghU0jcOAZgWXZ1Dmrw==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -911,6 +953,12 @@ "tslib": "^2.4.0" } }, + "node_modules/@types/cookie": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.6.0.tgz", + "integrity": "sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==", + "license": "MIT" + }, "node_modules/@types/json5": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", @@ -1657,6 +1705,15 @@ "dev": true, "license": "MIT" }, + "node_modules/cookie": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz", + "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -1689,7 +1746,6 @@ "version": "3.1.3", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==", - "dev": true, "license": "MIT" }, "node_modules/damerau-levenshtein": { @@ -2952,6 +3008,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/goober": { + "version": "2.1.16", + "resolved": "https://registry.npmjs.org/goober/-/goober-2.1.16.tgz", + "integrity": "sha512-erjk19y1U33+XAMe1VTvIONHYoSqE4iS7BYUZfHaqeohLmnC0FdxEh7rQU+6MZ4OajItzjZFSRtVANrQwNq6/g==", + "license": "MIT", + "peerDependencies": { + "csstype": "^3.0.10" + } + }, "node_modules/gopd": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", @@ -3627,6 +3692,15 @@ "jiti": "bin/jiti.js" } }, + "node_modules/jose": { + "version": "5.9.4", + "resolved": "https://registry.npmjs.org/jose/-/jose-5.9.4.tgz", + "integrity": "sha512-WBBl6au1qg6OHj67yCffCgFR3BADJBXN8MdRvCgJDuMv3driV2nHr7jdGvaKX9IolosAsn+M0XRArqLXUhyJHQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, "node_modules/js-sha256": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.11.0.tgz", @@ -3960,6 +4034,33 @@ } } }, + "node_modules/next-auth": { + "version": "5.0.0-beta.22", + "resolved": "https://registry.npmjs.org/next-auth/-/next-auth-5.0.0-beta.22.tgz", + "integrity": "sha512-QGBo9HGOjmnJBHGXvtFztl0tM5tL0porDlk74HVoCCzXd986ApOlIW3EmiCuho7YzEopgkFiwwmcXpoCrHAtYw==", + "license": "ISC", + "dependencies": { + "@auth/core": "0.35.3" + }, + "peerDependencies": { + "@simplewebauthn/browser": "^9.0.1", + "@simplewebauthn/server": "^9.0.2", + "next": "^14.0.0-0 || ^15.0.0-0", + "nodemailer": "^6.6.5", + "react": "^18.2.0 || ^19.0.0-0" + }, + "peerDependenciesMeta": { + "@simplewebauthn/browser": { + "optional": true + }, + "@simplewebauthn/server": { + "optional": true + }, + "nodemailer": { + "optional": true + } + } + }, "node_modules/next/node_modules/postcss": { "version": "8.4.31", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz", @@ -3998,6 +4099,15 @@ "node": ">=0.10.0" } }, + "node_modules/oauth4webapi": { + "version": "2.17.0", + "resolved": "https://registry.npmjs.org/oauth4webapi/-/oauth4webapi-2.17.0.tgz", + "integrity": "sha512-lbC0Z7uzAFNFyzEYRIC+pkSVvDHJTbEW+dYlSBAlCYDe6RxUkJ26bClhk8ocBZip1wfI9uKTe0fm4Ib4RHn6uQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -4493,6 +4603,28 @@ "dev": true, "license": "MIT" }, + "node_modules/preact": { + "version": "10.11.3", + "resolved": "https://registry.npmjs.org/preact/-/preact-10.11.3.tgz", + "integrity": "sha512-eY93IVpod/zG3uMF22Unl8h9KkrcKIRs2EGar8hwLZZDU1lkjph303V9HZBwufh2s736U6VXuhD109LYqPoffg==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/preact" + } + }, + "node_modules/preact-render-to-string": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/preact-render-to-string/-/preact-render-to-string-5.2.3.tgz", + "integrity": "sha512-aPDxUn5o3GhWdtJtW0svRC2SS/l8D9MAgo2+AWml+BhDImb27ALf04Q2d+AHqUUOc6RdSXFIBVa2gxzgMKgtZA==", + "license": "MIT", + "dependencies": { + "pretty-format": "^3.8.0" + }, + "peerDependencies": { + "preact": ">=10" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -4503,6 +4635,12 @@ "node": ">= 0.8.0" } }, + "node_modules/pretty-format": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-3.8.0.tgz", + "integrity": "sha512-WuxUnVtlWL1OfZFQFuqvnvs6MiAGk9UNsBostyBOB0Is9wb5uRESevA6rnl/rkksXaGX3GzZhPup5d6Vp1nFew==", + "license": "MIT" + }, "node_modules/prisma": { "version": "5.19.0", "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.19.0.tgz", @@ -4593,6 +4731,22 @@ "react": "^18.3.1" } }, + "node_modules/react-hot-toast": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/react-hot-toast/-/react-hot-toast-2.4.1.tgz", + "integrity": "sha512-j8z+cQbWIM5LY37pR6uZR6D4LfseplqnuAO4co4u8917hBUvXlEqyP1ZzqVLcqoyUesZZv/ImreoCeHVDpE5pQ==", + "license": "MIT", + "dependencies": { + "goober": "^2.1.10" + }, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "react": ">=16", + "react-dom": ">=16" + } + }, "node_modules/react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", diff --git a/package.json b/package.json index 2229bc3..320555d 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,8 @@ "@prisma/client": "^5.18.0", "js-sha256": "^0.11.0", "next": "^15.0.0-canary.195", + "next-auth": "^5.0.0-beta.22", + "react-hot-toast": "^2.4.1", "ua-parser-js": "^1.0.38", "zod": "^3.23.8" }, diff --git a/src/actions/block_actions.ts b/src/actions/block_actions.ts index 318fa27..444a47a 100644 --- a/src/actions/block_actions.ts +++ b/src/actions/block_actions.ts @@ -1,8 +1,9 @@ "use server" -import { z } from "zod"; +import { set, z } from "zod"; import prisma from "../../prisma/prisma"; import { revalidatePath } from "next/cache"; +import toast from "react-hot-toast"; export async function createLinkBlock(prevState: any, formData: FormData) { @@ -63,7 +64,7 @@ export async function createLinkBlock(prevState: any, formData: FormData) { }); } catch (e: any) { return { - message: "Error creating link block", + message: "Error adding link to page", error: e.message }; } @@ -73,7 +74,7 @@ export async function createLinkBlock(prevState: any, formData: FormData) { revalidatePath(`/${customPage.page.shortcode}`); return { - message: "Link block created" + message: "Adding link to page" }; } @@ -93,16 +94,22 @@ export async function deleteLinkBlock(prevState: any, formData: FormData) { }; } - await prisma.linkBlock.delete({ - where: { - uuid: data.data.uuid - } - }); + try { + await prisma.linkBlock.delete({ + where: { + uuid: data.data.uuid + } + }); + } catch (e: any) { + return { + message: "Cant delete link from page", + }; + } revalidatePath("/~/dash"); return { - message: "Link block deleted" + message: "Removed link from page" }; } diff --git a/src/actions/page_actions.ts b/src/actions/page_actions.ts index 50843d4..728885a 100644 --- a/src/actions/page_actions.ts +++ b/src/actions/page_actions.ts @@ -49,7 +49,7 @@ export async function createCustomPage(prevState: any, fromData: FormData) { message: "Shortcode already exists", error: { shortcode: ["Shortcode already exists"] - + } }; } @@ -149,13 +149,16 @@ export async function deletePage(prevState: any, fromData: FormData) { } + export async function pinPageToRoot(prevState: any, fromData: FormData) { const schema = z.object({ - uuid: z.string().uuid() + uuid: z.string().uuid(), + unpin: z.enum(['true', 'false']).transform((value) => value === 'true').optional() }); const data = schema.safeParse({ - uuid: fromData.get("uuid") + uuid: fromData.get("uuid"), + unpin: fromData.get("unpin") }); if (!data.success) { @@ -165,24 +168,43 @@ export async function pinPageToRoot(prevState: any, fromData: FormData) { }; } - await prisma.pinnedPage.upsert({ - where: { - id: 1 - }, - update: { - pageUuid: data.data.uuid - }, - create: { - id: 1, - pageUuid: data.data.uuid - } - }); - revalidatePath("/~/dash"); - revalidatePath("/"); - return { - message: "Page pinned", - }; + console.log(data.data.unpin); + if (data.data.unpin) { + + console.log + + await prisma.pinnedPage.delete({ + where: { + id: 1 + } + }); + revalidatePath("/~/dash"); + revalidatePath("/"); + return { + message: "Page unpinned", + }; + } else { + await prisma.pinnedPage.upsert({ + where: { + id: 1 + }, + update: { + pageUuid: data.data.uuid + }, + create: { + id: 1, + pageUuid: data.data.uuid + } + }); + + revalidatePath("/~/dash"); + revalidatePath("/"); + + return { + message: "Page pinned", + }; + } } \ No newline at end of file diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts new file mode 100644 index 0000000..0cf1408 --- /dev/null +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -0,0 +1,2 @@ +import { handlers } from "@/auth" // Referring to the auth.ts we just created +export const { GET, POST } = handlers \ No newline at end of file diff --git a/src/app/globals.css b/src/app/globals.css index d38c1e0..e88ed0d 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -2,17 +2,16 @@ @tailwind components; @tailwind utilities; - body { - @apply text-gray-300 bg-gray-900 + @apply text-gray-300 bg-gray-900; } h1 { - @apply text-5xl font-bold mb-6 + @apply text-5xl font-bold mb-6; } h2 { - @apply text-2xl font-bold mb-4 + @apply text-2xl font-bold mb-4; } .form-group { @@ -44,13 +43,68 @@ label { } button { - @apply rounded bg-green-600 hover:bg-green-700 text-white py-2 px-4 disabled:opacity-50 + @apply rounded bg-green-600 hover:bg-green-700 text-white py-2 px-4 disabled:opacity-50; +} + +.button-icon { + @apply h-5 w-5 inline-block align-middle; } .zebra { - @apply odd:bg-slate-800 p-2 rounded + @apply odd:bg-slate-800 p-2 rounded; } .common-red { - @apply text-red-500 -} \ No newline at end of file + @apply text-red-500; +} + +@keyframes slide-in { + 0% { + transform: translateY(-30px); + opacity: 0; + } + 100% { + transform: translateY(0); + opacity: 1; + } +} + +.slide-animated { + animation: slide-in 0.7s ease forwards; + opacity: 0; +} + +@keyframes zoom-in { + 0% { + transform: scale(0.7); + opacity: 0; + } + 100% { + transform: scale(1); + opacity: 1; + } +} + +.zoom-animated { + animation: zoom-in 1.5s ease forwards; + transform: scale(0.7); +} + +@keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } +} + +.fade-animated { + animation: fade-in 0.7s ease forwards; + opacity: 0; +} + +.vcenter { + @apply flex items-center flex-col justify-center mt-5; + min-height: 80vh; +} diff --git a/src/app/page.tsx b/src/app/page.tsx index 96a6cea..1b8f6df 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -5,18 +5,20 @@ import { redirect } from "next/navigation"; export default async function Home() { - const pinnedPage = await prisma.pinnedPage.findFirst({where: {id: 1}, include: {page: true}}); + const pinnedPage = await prisma.pinnedPage.findFirst({ where: { id: 1 }, include: { page: true } }); if (pinnedPage) { redirect(pinnedPage.page.shortcode); } return ( - (<> -

Home

+ (
+

Welcome

This is a url shortner

- Dashboard - +

Currently there is no default root page defined

+ Set pin a page in the dashboard + Or check out the project page +
) ); } diff --git a/src/app/~/dash/[uuid]/page.tsx b/src/app/~/dash/[uuid]/page.tsx index 09aa8ba..6e98108 100644 --- a/src/app/~/dash/[uuid]/page.tsx +++ b/src/app/~/dash/[uuid]/page.tsx @@ -7,6 +7,7 @@ import CustomPageDashboard from "@/components/CustomPageDashboard"; import LinkFavicon from "@/components/LinkFavicon"; import { hashToColor } from "@/utils"; import PinPageToRootForm from "@/components/forms/pinPageToRootForm"; +import { ArrowTopRightOnSquareIcon } from "@heroicons/react/24/solid"; interface PageProps { params: Promise<{ @@ -14,8 +15,8 @@ interface PageProps { }> } -export default async function DetailedStats({ params } : PageProps) { - +export default async function DetailedStats({ params }: PageProps) { + const { uuid } = await params; const page = await prisma.page.findUnique({ @@ -87,13 +88,13 @@ export default async function DetailedStats({ params } : PageProps) {

{page.redirectPage[0].dest}

: ""}
- {page.pinnedPage ?

Pinned to root

: ""} + {page.pinnedPage ?

Pinned to root

: ""}
- +
- +
diff --git a/src/app/~/dash/layout.tsx b/src/app/~/dash/layout.tsx index 920f436..75a8632 100644 --- a/src/app/~/dash/layout.tsx +++ b/src/app/~/dash/layout.tsx @@ -2,14 +2,36 @@ import Link from 'next/link'; import React, { ReactNode } from 'react'; +import { Toaster } from "react-hot-toast"; +import { auth } from "@/auth"; +import { redirect } from 'next/navigation'; +import SignOutButton from '@/components/forms/signOutButton'; -export default function Dashboard({ children }: { children: ReactNode }) { +export default async function Dashboard({ children }: { children: ReactNode }) { + + const session = await auth(); + const awSession = await session; + const user = awSession?.user; + + if (!user) { + redirect("/~/"); + } + return (
- -

Dashboard

- +
+ + +

Dashboard

+ +
+ {user?.name ? <> +
{user?.name || user.email}
+ : ""} +
+
+ {children}
); diff --git a/src/app/~/dash/page.tsx b/src/app/~/dash/page.tsx index c308955..be167af 100644 --- a/src/app/~/dash/page.tsx +++ b/src/app/~/dash/page.tsx @@ -20,6 +20,7 @@ export default async function Dashboard() { const redirectPages = pages.filter((page) => page.redirectPage.length > 0); const customPages = pages.filter((page) => page.customPage.length > 0); + const pinnedPage = await prisma.pinnedPage.findFirst({ where: { id: 1 } }); return (<>

Redirect Pages

diff --git a/src/app/~/page.tsx b/src/app/~/page.tsx new file mode 100644 index 0000000..4bbd194 --- /dev/null +++ b/src/app/~/page.tsx @@ -0,0 +1,24 @@ +import { auth } from "@/auth"; +import SignInButton from "@/components/forms/signInButton"; +import Link from "next/link"; +import { redirect } from "next/navigation"; + +export default async function AdminRoot() { + + const session = await auth(); + const awSession = await session; + const user = awSession?.user; + + if (user) { + redirect("/~/dash/"); + } + + return (
+ +

traberph/short

+ + or back to root +
+ ) + +} \ No newline at end of file diff --git a/src/auth.ts b/src/auth.ts new file mode 100644 index 0000000..5f40771 --- /dev/null +++ b/src/auth.ts @@ -0,0 +1,6 @@ +import NextAuth from "next-auth" +import Authentik from "next-auth/providers/authentik" + +export const { handlers, signIn, signOut, auth } = NextAuth({ + providers: [Authentik], +}) \ No newline at end of file diff --git a/src/components/CustomPageComponent.tsx b/src/components/CustomPageComponent.tsx index cd09d41..77c58ac 100644 --- a/src/components/CustomPageComponent.tsx +++ b/src/components/CustomPageComponent.tsx @@ -19,20 +19,24 @@ export default async function CustomPageComponent(params: { customPage: CustomPa }); return ( -
+
 -

{customPage.title}

-
+

{customPage.title}

+
- {linkBlocks.map((block) => ( - ))}
-
traberph/short by me running on K3s
+
+ traberph/short by me running on K3s +
); } \ No newline at end of file diff --git a/src/components/CustomPageDashboard.tsx b/src/components/CustomPageDashboard.tsx index a1adbc4..a9aca8d 100644 --- a/src/components/CustomPageDashboard.tsx +++ b/src/components/CustomPageDashboard.tsx @@ -2,6 +2,7 @@ import { CustomPage } from "@prisma/client" import prisma from "../../prisma/prisma" import CreateLinkBlockForm from "./forms/createLinkBlockForm" import DeleteLinkBlockForm from "./forms/deleteLinkBlockForm" +import { ArrowTopRightOnSquareIcon, ArrowTrendingUpIcon, ArrowUpCircleIcon, ArrowUpRightIcon } from "@heroicons/react/24/solid" export default async function CustomPageDashboard(params: { customPage: CustomPage }) { @@ -30,12 +31,12 @@ export default async function CustomPageDashboard(params: { customPage: CustomPa
connected link page: {block.redirectPage.page.shortcode}
diff --git a/src/components/forms/createCustomPageForm.tsx b/src/components/forms/createCustomPageForm.tsx index 012753c..f62f573 100644 --- a/src/components/forms/createCustomPageForm.tsx +++ b/src/components/forms/createCustomPageForm.tsx @@ -1,7 +1,8 @@ "use client" import { createCustomPage } from "@/actions/page_actions"; -import { useActionState } from "react"; +import { useActionState, useEffect } from "react"; import SubmitButton from "../SubmitButton"; +import { handleToast } from "@/utils"; export default function CreateCustomPageForm() { @@ -13,6 +14,8 @@ export default function CreateCustomPageForm() { const [state, formAction] = useActionState(createCustomPage, initialState); + useEffect(() => { handleToast(state); }, [state]); + return (
diff --git a/src/components/forms/createLinkBlockForm.tsx b/src/components/forms/createLinkBlockForm.tsx index 6420be0..232faea 100644 --- a/src/components/forms/createLinkBlockForm.tsx +++ b/src/components/forms/createLinkBlockForm.tsx @@ -1,7 +1,10 @@ "use client" import { createLinkBlock } from "@/actions/block_actions" -import { useActionState } from "react"; +import { useActionState, useEffect } from "react"; import SubmitButton from "../SubmitButton"; +import toast from "react-hot-toast"; +import { handleToast } from "@/utils"; +import { LinkIcon } from "@heroicons/react/24/solid"; export default function CreateLinkBlockForm({ customPage, shortcodes }: { customPage: string, shortcodes: string[] }) { @@ -13,6 +16,8 @@ export default function CreateLinkBlockForm({ customPage, shortcodes }: { custom const [state, formAction] = useActionState(createLinkBlock, initialState); + useEffect(() => { handleToast(state); }, [state]); + return (
@@ -32,8 +37,7 @@ export default function CreateLinkBlockForm({ customPage, shortcodes }: { custom

{state.error?.order}

-

{state.message}

- add to page + add to page ); diff --git a/src/components/forms/createRedirectPageForm.tsx b/src/components/forms/createRedirectPageForm.tsx index f82d6f4..fb93215 100644 --- a/src/components/forms/createRedirectPageForm.tsx +++ b/src/components/forms/createRedirectPageForm.tsx @@ -1,8 +1,10 @@ "use client" import { createRedirectPage } from "@/actions/page_actions"; -import { useActionState } from "react"; +import { useActionState, useEffect } from "react"; import SubmitButton from "../SubmitButton"; +import toast from "react-hot-toast"; +import { handleToast } from "@/utils"; export default function CreateRedirectPageForm() { const initialState = { @@ -11,6 +13,8 @@ export default function CreateRedirectPageForm() { }; const [state, formAction] = useActionState(createRedirectPage, initialState); + useEffect(() => { handleToast(state); }, [state]); + return (
@@ -23,7 +27,6 @@ export default function CreateRedirectPageForm() {

{state.error?.dest}

-

{state.message}

); diff --git a/src/components/forms/deleteLinkBlockForm.tsx b/src/components/forms/deleteLinkBlockForm.tsx index 2c8d49b..313ad6d 100644 --- a/src/components/forms/deleteLinkBlockForm.tsx +++ b/src/components/forms/deleteLinkBlockForm.tsx @@ -1,10 +1,12 @@ "use client" import { deleteLinkBlock } from "@/actions/block_actions"; -import { useActionState } from "react"; +import { useActionState, useEffect } from "react"; import SubmitButton from "../SubmitButton"; +import { handleToast } from "@/utils"; +import { LinkSlashIcon } from "@heroicons/react/24/solid"; -export default function DeleteLinkBlockForm({linkBlockUuid}: {linkBlockUuid:string}) { +export default function DeleteLinkBlockForm({ linkBlockUuid }: { linkBlockUuid: string }) { const initialState = { message: "", @@ -13,11 +15,14 @@ export default function DeleteLinkBlockForm({linkBlockUuid}: {linkBlockUuid:stri const [state, formAction] = useActionState(deleteLinkBlock, initialState); - return (
+ useEffect(() => { handleToast(state); }, [state]); - - unlink + return ( + + + +
) - + } \ No newline at end of file diff --git a/src/components/forms/deletePageForm.tsx b/src/components/forms/deletePageForm.tsx index a9bbf85..9174902 100644 --- a/src/components/forms/deletePageForm.tsx +++ b/src/components/forms/deletePageForm.tsx @@ -1,22 +1,26 @@ "use client" import { deletePage } from "@/actions/page_actions"; -import { useActionState } from "react"; +import { useActionState, useEffect } from "react"; import SubmitButton from "../SubmitButton"; -import { redirect } from "next/navigation"; +import toast from "react-hot-toast"; +import { handleToast } from "@/utils"; +import { TrashIcon } from "@heroicons/react/24/solid"; -export default function DeletePageForm({uuid}: {uuid: string}) { +export default function DeletePageForm({ uuid }: { uuid: string }) { const initialState = { message: "", error: {}, - }; + }; const [state, formAction] = useActionState(deletePage, initialState); + useEffect(() => { handleToast(state); }, [state]); + return (
- - Delete + +
); diff --git a/src/components/forms/pinPageToRootForm.tsx b/src/components/forms/pinPageToRootForm.tsx index 9d34fe6..b5ac348 100644 --- a/src/components/forms/pinPageToRootForm.tsx +++ b/src/components/forms/pinPageToRootForm.tsx @@ -1,9 +1,11 @@ "use client" import { pinPageToRoot } from "@/actions/page_actions"; -import { BookmarkIcon } from "@heroicons/react/24/solid"; -import { useActionState, useState } from "react"; +import { handleToast } from "@/utils"; +import { BookmarkIcon, BookmarkSlashIcon } from "@heroicons/react/24/solid"; +import { use, useActionState, useEffect, useState } from "react"; +import { toast } from 'react-hot-toast'; -export default function PinPageToRootForm({ pageUuid, disabled }: { pageUuid: string, disabled: boolean }) { +export default function PinPageToRootForm({ pageUuid, pinned }: { pageUuid: string, pinned: boolean }) { const initialState = { message: "", @@ -12,10 +14,17 @@ export default function PinPageToRootForm({ pageUuid, disabled }: { pageUuid: st const [state, formAction] = useActionState(pinPageToRoot, initialState); + useEffect(() => { handleToast(state); }, [state]); - return (
+ return ( - {/*

{state.message}

*/} - + +
) } \ No newline at end of file diff --git a/src/components/forms/signInButton.tsx b/src/components/forms/signInButton.tsx new file mode 100644 index 0000000..ebcce2d --- /dev/null +++ b/src/components/forms/signInButton.tsx @@ -0,0 +1,15 @@ +import { signIn } from "@/auth" + +export default function SignInButton() { + return (
+
{ + "use server" + await signIn("authentik") + }} + > + +
+
+ ) +} \ No newline at end of file diff --git a/src/components/forms/signOutButton.tsx b/src/components/forms/signOutButton.tsx new file mode 100644 index 0000000..0a135e3 --- /dev/null +++ b/src/components/forms/signOutButton.tsx @@ -0,0 +1,15 @@ +import { signOut } from "@/auth" + +export default function SignOutButton() { + return ( +
{ + "use server" + await signOut() + }} + > + +
+ ) +} \ No newline at end of file diff --git a/src/middleware.ts b/src/middleware.ts new file mode 100644 index 0000000..2df914b --- /dev/null +++ b/src/middleware.ts @@ -0,0 +1 @@ +export { auth as middleware } from "@/auth" \ No newline at end of file diff --git a/src/utils.tsx b/src/utils.tsx index 4ef2efa..7902739 100644 --- a/src/utils.tsx +++ b/src/utils.tsx @@ -1,4 +1,6 @@ -export function hashToColor(hash: string|null): string { +import toast from "react-hot-toast"; + +export function hashToColor(hash: string | null): string { if (!hash) { return "black"; } @@ -7,4 +9,15 @@ export function hashToColor(hash: string|null): string { const b = parseInt(hash.slice(4, 6), 16); const color = `rgb(${r}, ${g}, ${b})`; return color; +} + +export function handleToast(state: { message: string, error?: any }) { + if (state.message) { + console.log(state); + if (state.error) { + toast.error(state.message); + } else { + toast.success(state.message); + } + } } \ No newline at end of file