diff --git a/app/actions/login.tsx b/app/actions/login.tsx new file mode 100644 index 0000000..7f7a36f --- /dev/null +++ b/app/actions/login.tsx @@ -0,0 +1,29 @@ +"use server" + +import { pkceConfig } from "@/lib/cookieConfig"; +import crypto from "crypto" +import { cookies } from "next/headers"; +import { redirect } from "next/navigation"; + +export default async function login() { + const verifier = crypto.randomBytes(32).toString("base64url"); + const challenge = crypto.createHash("sha256").update(verifier).digest("base64url"); + const state = crypto.randomBytes(16).toString("hex"); + + const store = await cookies(); + + store.set("pkce_verifier", verifier, pkceConfig) + store.set("oauth_state", state, { ...pkceConfig, path: "/" }) + + const params = new URLSearchParams({ + client_id: process.env.KOTOSOFT_ID_CLIENT_ID!, + redirect_uri: `${process.env.PUBLIC_URL}/api/callback`, + scope: "profile:read", + response_type: "code", + code_challenge: challenge, + code_challenge_method: "S256", + state, + }); + + redirect(`${process.env.KOTOSOFT_ID_API_URL}/oauth/authorize?${params}`); +} \ No newline at end of file diff --git a/app/api/callback/route.ts b/app/api/callback/route.ts new file mode 100644 index 0000000..2e7c4af --- /dev/null +++ b/app/api/callback/route.ts @@ -0,0 +1,90 @@ +import { cookies } from "next/headers"; +import { NextRequest, NextResponse } from "next/server"; +import { deleteOAuthCookies, setTokens } from "@/lib/cookies"; +import { prisma } from "@/lib/prisma"; +import { setSessionCookie } from "@/lib/session"; +import { signJwt } from "@/lib/jwt"; +import { v4 as uuidv4 } from "uuid"; + +export async function GET(request: NextRequest) { + const searchParams = request.nextUrl.searchParams; + + const code = searchParams.get("code"); + const state = searchParams.get("state"); + + if (!code || !state) { + return NextResponse.json({ status: 409, message: "Incorrect request" }); + } + + const store = await cookies(); + + const codeVerifier = store.get("pkce_verifier")?.value; + const savedState = store.get("oauth_state")?.value; + + if (!codeVerifier || !savedState || savedState !== state) { + return NextResponse.json({ status: 403, message: "Access denied" }); + } + + const body = new URLSearchParams({ + grant_type: "authorization_code", + code, + redirect_uri: `${process.env.PUBLIC_URL}/api/callback`, + code_verifier: codeVerifier, + }); + + const response = await fetch(`${process.env.KOTOSOFT_ID_API_URL}/oauth/token`, { + method: "POST", + headers: { + "Content-Type": "application/x-www-form-urlencoded", + Authorization: `Basic ${Buffer.from( + `${process.env.KOTOSOFT_ID_CLIENT_ID}:${process.env.KOTOSOFT_ID_CLIENT_SECRET}` + ).toString("base64")}`, + }, + body, + }); + + if (!response.ok) { + console.log(response) + return NextResponse.redirect(new URL("/callback/error", request.url)); + } + + const data = await response.json(); + + await setTokens(data.access_token, data.refresh_token, data.expires_in); + + const user = await fetch(`${process.env.KOTOSOFT_ID_API_URL}/api/v1/me`, { + headers: { + Authorization: `Bearer ${data.access_token}`, + }, + }); + const userData = await user.json(); + + var existingUser = await prisma.user.findUnique({ + where: { + kotosoftId: userData.id, + } + }); + + if (!existingUser) { + const createdUser = await prisma.user.create({ + data: { + id: uuidv4(), + kotosoftId: userData.id, + email: userData.email, + firstName: userData.first_name, + secondName: userData.second_name, + sex: userData.sex, + birthDate: userData.birth_date, + }, + }); + + existingUser = createdUser!; + } + + const token = await signJwt(existingUser.id); + + await setSessionCookie(token); + await deleteOAuthCookies(); + + return NextResponse.redirect(new URL("/", request.url)); +} \ No newline at end of file diff --git a/app/globals.css b/app/globals.css index a2dc41e..9c168c6 100644 --- a/app/globals.css +++ b/app/globals.css @@ -1,26 +1,145 @@ @import "tailwindcss"; +@import "tw-animate-css"; +@import "shadcn/tailwind.css"; -:root { - --background: #ffffff; - --foreground: #171717; -} +@custom-variant dark (&:is(.dark *)); @theme inline { --color-background: var(--background); --color-foreground: var(--foreground); - --font-sans: var(--font-geist-sans); + --font-sans: var(--font-sans); --font-mono: var(--font-geist-mono); + --font-heading: var(--font-sans); + --color-sidebar-ring: var(--sidebar-ring); + --color-sidebar-border: var(--sidebar-border); + --color-sidebar-accent-foreground: var(--sidebar-accent-foreground); + --color-sidebar-accent: var(--sidebar-accent); + --color-sidebar-primary-foreground: var(--sidebar-primary-foreground); + --color-sidebar-primary: var(--sidebar-primary); + --color-sidebar-foreground: var(--sidebar-foreground); + --color-sidebar: var(--sidebar); + --color-chart-5: var(--chart-5); + --color-chart-4: var(--chart-4); + --color-chart-3: var(--chart-3); + --color-chart-2: var(--chart-2); + --color-chart-1: var(--chart-1); + --color-ring: var(--ring); + --color-input: var(--input); + --color-border: var(--border); + --color-destructive: var(--destructive); + --color-accent-foreground: var(--accent-foreground); + --color-accent: var(--accent); + --color-muted-foreground: var(--muted-foreground); + --color-muted: var(--muted); + --color-secondary-foreground: var(--secondary-foreground); + --color-secondary: var(--secondary); + --color-primary-foreground: var(--primary-foreground); + --color-primary: var(--primary); + --color-popover-foreground: var(--popover-foreground); + --color-popover: var(--popover); + --color-card-foreground: var(--card-foreground); + --color-card: var(--card); + --radius-sm: calc(var(--radius) * 0.6); + --radius-md: calc(var(--radius) * 0.8); + --radius-lg: var(--radius); + --radius-xl: calc(var(--radius) * 1.4); + --radius-2xl: calc(var(--radius) * 1.8); + --radius-3xl: calc(var(--radius) * 2.2); + --radius-4xl: calc(var(--radius) * 2.6); } -@media (prefers-color-scheme: dark) { - :root { - --background: #0a0a0a; - --foreground: #ededed; +:root { + --background: oklch(1 0 0); + --foreground: oklch(0.145 0 0); + --card: oklch(1 0 0); + --card-foreground: oklch(0.145 0 0); + --popover: oklch(1 0 0); + --popover-foreground: oklch(0.145 0 0); + --primary: oklch(0.205 0 0); + --primary-foreground: oklch(0.985 0 0); + --secondary: oklch(0.97 0 0); + --secondary-foreground: oklch(0.205 0 0); + --muted: oklch(0.97 0 0); + --muted-foreground: oklch(0.556 0 0); + --accent: oklch(0.97 0 0); + --accent-foreground: oklch(0.205 0 0); + --destructive: oklch(0.577 0.245 27.325); + --border: oklch(0.922 0 0); + --input: oklch(0.922 0 0); + --ring: oklch(0.708 0 0); + --chart-1: oklch(0.87 0 0); + --chart-2: oklch(0.556 0 0); + --chart-3: oklch(0.439 0 0); + --chart-4: oklch(0.371 0 0); + --chart-5: oklch(0.269 0 0); + --radius: 0.625rem; + --sidebar: oklch(0.985 0 0); + --sidebar-foreground: oklch(0.145 0 0); + --sidebar-primary: oklch(0.205 0 0); + --sidebar-primary-foreground: oklch(0.985 0 0); + --sidebar-accent: oklch(0.97 0 0); + --sidebar-accent-foreground: oklch(0.205 0 0); + --sidebar-border: oklch(0.922 0 0); + --sidebar-ring: oklch(0.708 0 0); +} + +.dark { + --background: oklch(0.145 0 0); + --foreground: oklch(0.985 0 0); + --card: oklch(0.205 0 0); + --card-foreground: oklch(0.985 0 0); + --popover: oklch(0.205 0 0); + --popover-foreground: oklch(0.985 0 0); + --primary: oklch(0.922 0 0); + --primary-foreground: oklch(0.205 0 0); + --secondary: oklch(0.269 0 0); + --secondary-foreground: oklch(0.985 0 0); + --muted: oklch(0.269 0 0); + --muted-foreground: oklch(0.708 0 0); + --accent: oklch(0.269 0 0); + --accent-foreground: oklch(0.985 0 0); + --destructive: oklch(0.704 0.191 22.216); + --border: oklch(1 0 0 / 10%); + --input: oklch(1 0 0 / 15%); + --ring: oklch(0.556 0 0); + --chart-1: oklch(0.87 0 0); + --chart-2: oklch(0.556 0 0); + --chart-3: oklch(0.439 0 0); + --chart-4: oklch(0.371 0 0); + --chart-5: oklch(0.269 0 0); + --sidebar: oklch(0.205 0 0); + --sidebar-foreground: oklch(0.985 0 0); + --sidebar-primary: oklch(0.488 0.243 264.376); + --sidebar-primary-foreground: oklch(0.985 0 0); + --sidebar-accent: oklch(0.269 0 0); + --sidebar-accent-foreground: oklch(0.985 0 0); + --sidebar-border: oklch(1 0 0 / 10%); + --sidebar-ring: oklch(0.556 0 0); +} + +@layer base { + * { + @apply border-border outline-ring/50; + } + body { + @apply bg-background text-foreground; + } + button:not(:disabled), [role="button"]:not(:disabled) { + cursor: pointer; + } + html { + @apply font-sans; } } -body { - background: var(--background); - color: var(--foreground); - font-family: Arial, Helvetica, sans-serif; +h1 { + @apply text-3xl tracking-tight } + +h2 { + @apply text-2xl tracking-tight +} + +h3 { + @apply text-xl tracking-tight +} \ No newline at end of file diff --git a/app/layout.tsx b/app/layout.tsx index 976eb90..6da82d2 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,20 +1,16 @@ import type { Metadata } from "next"; -import { Geist, Geist_Mono } from "next/font/google"; +import localFont from "next/font/local" import "./globals.css"; +import { cn } from "@/lib/utils"; -const geistSans = Geist({ - variable: "--font-geist-sans", - subsets: ["latin"], -}); - -const geistMono = Geist_Mono({ - variable: "--font-geist-mono", - subsets: ["latin"], -}); +const helvetica = localFont({ + src: "../public/fonts/HelveticaNeue-Medium.otf", + weight: "500" +}) export const metadata: Metadata = { - title: "Create Next App", - description: "Generated by create next app", + title: "European Federation", + description: "Official site of the European Federation", }; export default function RootLayout({ @@ -25,7 +21,7 @@ export default function RootLayout({ return ( {children} diff --git a/app/page.tsx b/app/page.tsx index 3f36f7c..5b6ccf4 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,65 +1,63 @@ -import Image from "next/image"; +import Footer from "@/components/footer"; +import Header from "@/components/header"; +import { Badge } from "@/components/ui/badge" +import { ArrowRight, Calendar, Globe2 } from "lucide-react"; export default function Home() { return ( -
-
- Next.js logo -
-

- To get started, edit the page.tsx file. -

-

- Looking for a starting point or more instructions? Head over to{" "} - - Templates - {" "} - or the{" "} - - Learning - {" "} - center. -

+ <> +
+
+

Welcome to the European Federation!

+
+
+

Become a citizen

+
+
+
+

Learn more about the President

+
+
+

Acknowledge with the Federal Government

+
+
+
+
+

Regions of the Federation

+
+
+

Receive consular services abroad

+
+
-
- - Vercel logomark - Deploy Now - - - Documentation - +
+

Recent news

+
+

Construction of the White House has started

+
+

16 June, 2026

+

Liberty City

+
+ Liberty City +
+
+
+
+

President Volokhov has visited the Liberty City Trainbuilding Plant

+
+

16 June, 2026

+

Liberty City

+
+ President + Liberty City + Industry +
+
+
+

See all news

-
-
+ +