create auth session provider
This commit is contained in:
@@ -4,6 +4,7 @@ import "./globals.css";
|
|||||||
import { ThemeProvider } from "next-themes";
|
import { ThemeProvider } from "next-themes";
|
||||||
import { ModeToggle } from "@/components/mode-toggle";
|
import { ModeToggle } from "@/components/mode-toggle";
|
||||||
import SignIn from "./components/sign-in";
|
import SignIn from "./components/sign-in";
|
||||||
|
import AuthSessionProvider from "@/components/SessionProvider";
|
||||||
|
|
||||||
const geist = Geist({ subsets: ['latin', 'cyrillic'], variable: "--font-geist-sans" })
|
const geist = Geist({ subsets: ['latin', 'cyrillic'], variable: "--font-geist-sans" })
|
||||||
|
|
||||||
@@ -23,21 +24,23 @@ export default function RootLayout({
|
|||||||
<body
|
<body
|
||||||
className={`${geist.variable} antialiased min-h-screen flex flex-col dark:text-gray-300 --color-background`}
|
className={`${geist.variable} antialiased min-h-screen flex flex-col dark:text-gray-300 --color-background`}
|
||||||
>
|
>
|
||||||
<ThemeProvider
|
<AuthSessionProvider>
|
||||||
attribute="class"
|
<ThemeProvider
|
||||||
defaultTheme="system"
|
attribute="class"
|
||||||
enableSystem
|
defaultTheme="system"
|
||||||
disableTransitionOnChange
|
enableSystem
|
||||||
>
|
disableTransitionOnChange
|
||||||
<header className="dark:text-white text-gray-900 px-4 py-3 font-bold shadow flex justify-between items-center-safe">
|
>
|
||||||
{metadata.title as string || "iCal PWA"}
|
<header className="dark:text-white text-gray-900 px-4 py-3 font-bold shadow flex justify-between items-center-safe">
|
||||||
<div className="flex flex-row gap-2">
|
{metadata.title as string || "iCal PWA"}
|
||||||
<SignIn />
|
<div className="flex flex-row gap-2">
|
||||||
<ModeToggle />
|
<SignIn />
|
||||||
</div>
|
<ModeToggle />
|
||||||
</header>
|
</div>
|
||||||
<main className="flex-1 p-4">{children}</main>
|
</header>
|
||||||
</ThemeProvider>
|
<main className="flex-1 p-4">{children}</main>
|
||||||
|
</ThemeProvider>
|
||||||
|
</AuthSessionProvider>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
'use client'
|
"use client"
|
||||||
|
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { nanoid } from 'nanoid'
|
import { nanoid } from 'nanoid'
|
||||||
@@ -13,9 +13,9 @@ import { addEvent, deleteEvent, getAllEvents, clearEvents, getDB } from '@/lib/d
|
|||||||
import { parseICS, generateICS } from '@/lib/ical'
|
import { parseICS, generateICS } from '@/lib/ical'
|
||||||
import type { CalendarEvent } from '@/lib/types'
|
import type { CalendarEvent } from '@/lib/types'
|
||||||
import { Textarea } from '@/components/ui/textarea'
|
import { Textarea } from '@/components/ui/textarea'
|
||||||
import { auth } from '@/auth'
|
import { useSession } from 'next-auth/react'
|
||||||
|
|
||||||
export default async function HomePage() {
|
export default function HomePage() {
|
||||||
const [events, setEvents] = useState<CalendarEvent[]>([])
|
const [events, setEvents] = useState<CalendarEvent[]>([])
|
||||||
const [dialogOpen, setDialogOpen] = useState(false)
|
const [dialogOpen, setDialogOpen] = useState(false)
|
||||||
const [editingId, setEditingId] = useState<string | null>(null)
|
const [editingId, setEditingId] = useState<string | null>(null)
|
||||||
@@ -44,7 +44,7 @@ export default async function HomePage() {
|
|||||||
})()
|
})()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const session = await auth()
|
const { data: session, status } = useSession()
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
setTitle('')
|
setTitle('')
|
||||||
|
|||||||
12
src/components/SessionProvider.tsx
Normal file
12
src/components/SessionProvider.tsx
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { SessionProvider } from "next-auth/react"
|
||||||
|
import { ReactNode } from "react"
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
children: ReactNode
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function AuthSessionProvider({ children }: Props) {
|
||||||
|
return <SessionProvider>{children}</SessionProvider>
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user