-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
779 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
export default function Admin() { | ||
import { auth } from '~/utils/lib/auth' | ||
|
||
export default async function Admin() { | ||
const session = await auth() | ||
|
||
return ( | ||
<> | ||
控制台 | ||
控制台 {session?.user} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use server' | ||
|
||
import { AuthError } from 'next-auth' | ||
import { signIn } from '~/utils/lib/auth' | ||
|
||
export async function authenticate( | ||
email:string, password: string | ||
) { | ||
try { | ||
await signIn('credentials', { | ||
email: email, | ||
password: password, | ||
redirect: true, | ||
redirectTo: '/admin' | ||
}); | ||
} catch (error) { | ||
if (error instanceof AuthError) { | ||
switch (error.type) { | ||
case 'CredentialsSignin': | ||
return 'Invalid credentials.'; | ||
default: | ||
return 'Something went wrong.'; | ||
} | ||
} | ||
throw error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { GET, POST } from '~/utils/lib/auth' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use client' | ||
|
||
import React from 'react' | ||
import { Dropdown, DropdownTrigger, DropdownMenu, DropdownItem, Button } from '@nextui-org/react' | ||
import { useRouter } from 'next/navigation' | ||
import { getSession } from '~/utils/lib/session' | ||
|
||
export const DashDropMenu = async () => { | ||
const router = useRouter() | ||
const session = await getSession() | ||
|
||
return ( | ||
<> | ||
{ | ||
session ? | ||
<Dropdown> | ||
<DropdownTrigger> | ||
<span className="cursor-pointer select-none px-2"> | ||
菜单 | ||
</span> | ||
</DropdownTrigger> | ||
<DropdownMenu aria-label="Static Actions"> | ||
<DropdownItem key="new" onClick={() => router.push('/admin')}>后台</DropdownItem> | ||
<DropdownItem key="copy" onClick={() => { | ||
router.push('/') | ||
}}>退出登录</DropdownItem> | ||
</DropdownMenu> | ||
</Dropdown> | ||
: | ||
<div className="cursor-pointer select-none" onClick={() => router.push('/login')}> | ||
登录 | ||
</div> | ||
} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Link, Navbar, NavbarBrand, NavbarContent, NavbarItem } from '@nextui-org/react' | ||
import Logo from '~/components/Logo' | ||
import {GithubIcon} from '~/style/icons/GitHub' | ||
import DashNavbar from '~/components/DashNavbar' | ||
import React from 'react' | ||
|
||
export default function DashHeader() { | ||
return ( | ||
<Navbar> | ||
<NavbarBrand> | ||
<Logo/> | ||
</NavbarBrand> | ||
<NavbarContent className="hidden sm:flex gap-4 select-none" justify="center"> | ||
6 | ||
</NavbarContent> | ||
<NavbarContent justify="end"> | ||
<NavbarItem className="flex h-full items-center"> | ||
<Link | ||
isExternal | ||
aria-label="Github" | ||
className="p-1" | ||
href="https://github.com/besscroft/PicImpact" | ||
> | ||
<GithubIcon className="text-default-600 dark:text-default-500 dark:text-white" /> | ||
</Link> | ||
</NavbarItem> | ||
<NavbarItem className="flex h-full items-center space-x-2"> | ||
<DashNavbar /> | ||
</NavbarItem> | ||
</NavbarContent> | ||
</Navbar> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use client' | ||
|
||
import { useBreakpoints } from '~/utils/useBreakpoints' | ||
import { ThemeSwitch } from '~/components/DarkToggle' | ||
import DashVaulDrawer from '~/components/DashVaulDrawer' | ||
import { useHydrated } from '~/composables/react' | ||
import { DashDropMenu } from '~/components/DashDropMenu' | ||
import React from "react"; | ||
|
||
export default function DashNavbar() { | ||
const hydrated = useHydrated() | ||
const { smAndLarger } = useBreakpoints() | ||
|
||
return ( | ||
<> | ||
<button | ||
className="flex items-center space-x-2 md:hidden" | ||
> | ||
<DashDropMenu/> | ||
</button> | ||
{/*{ hydrated ? smAndLarger ? <ThemeSwitch/> : <DashVaulDrawer/> : null }*/} | ||
{/*{ hydrated && smAndLarger && <DashDropMenu/> }*/} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use client' | ||
|
||
import { Drawer } from 'vaul' | ||
import { useRouter } from 'next/navigation' | ||
import React from 'react'; | ||
import { Listbox, ListboxItem } from '@nextui-org/react' | ||
|
||
export default function DashVaulDrawer() { | ||
const router = useRouter() | ||
|
||
return ( | ||
<Drawer.Root> | ||
<Drawer.Trigger>菜单</Drawer.Trigger> | ||
<Drawer.Portal> | ||
<Drawer.Overlay className="fixed inset-0 bg-black/40 dark:bg-slate-800" /> | ||
<Drawer.Content className="bg-zinc-100 dark:bg-slate-900 flex flex-col rounded-t-[10px] h-[88%] mt-24 fixed bottom-0 left-0 right-0"> | ||
<div className="p-4 bg-white dark:bg-slate-900 rounded-t-[10px] flex-1"> | ||
<div className="mx-auto w-12 h-1.5 flex-shrink-0 rounded-full bg-zinc-300 mb-8" /> | ||
<div className="flex flex-col gap-4"> | ||
<div className="w-full px-1 py-2 rounded-small"> | ||
<Listbox | ||
aria-label="Actions" | ||
> | ||
<ListboxItem key="new">菜单1</ListboxItem> | ||
<ListboxItem key="copy">菜单2</ListboxItem> | ||
<ListboxItem key="edit">菜单3</ListboxItem> | ||
<ListboxItem key="delete" className="text-danger" color="danger"> | ||
菜单4 | ||
</ListboxItem> | ||
</Listbox> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="p-4 bg-zinc-100 dark:bg-slate-800 border-t border-zinc-200 mt-auto"> | ||
<div className="flex gap-6 justify-end max-w-md mx-auto"> | ||
<a | ||
className="text-xs text-zinc-600 flex items-center gap-0.25" | ||
href="https://github.com/besscroft" | ||
target="_blank" | ||
> | ||
GitHub | ||
<svg | ||
fill="none" | ||
height="16" | ||
stroke="currentColor" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="2" | ||
viewBox="0 0 24 24" | ||
width="16" | ||
aria-hidden="true" | ||
className="w-3 h-3 ml-1" | ||
> | ||
<path d="M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"></path> | ||
<path d="M15 3h6v6"></path> | ||
<path d="M10 14L21 3"></path> | ||
</svg> | ||
</a> | ||
</div> | ||
</div> | ||
</Drawer.Content> | ||
</Drawer.Portal> | ||
</Drawer.Root> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.