Skip to content

Commit 853504a

Browse files
committed
feat: upgrade authjs & login page
1 parent 41cb814 commit 853504a

File tree

11 files changed

+42
-86
lines changed

11 files changed

+42
-86
lines changed

apps/web/@/actions/auth/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
"use server"
22

3-
import { signIn } from "configs/auth"
3+
import { signIn, signOut } from "configs/auth"
44

55
export const signInWithCredentials = async (email: string, password: string) => {
6-
console.log(">>>>>", email, password)
76
await signIn("credentials", {
87
email,
98
password,
@@ -13,3 +12,9 @@ export const signInWithCredentials = async (email: string, password: string) =>
1312
export const signInWithGithub = async () => {
1413
await signIn("github")
1514
}
15+
16+
export const onSignOut = async () => {
17+
await signOut({
18+
redirectTo: "/",
19+
})
20+
}

apps/web/@/actions/manage-post/index.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

apps/web/@/constants/routes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const APP_ROUTES = {
22
// Public routes
33
HOME: "/",
44

5-
LOGIN: "/sign-in",
6-
REGISTER: "/register",
5+
LOGIN: "/signin",
6+
REGISTER: "/signup",
77
FORGOT_PASSWORD: "/forgot-password",
88
RESET_PASSWORD: "/reset-password",
99
VERIFY_EMAIL: "/verify-email",

apps/web/@/molecules/nav/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default async function Nav() {
4444
<div className="flex w-20 items-center">
4545
<Link
4646
className="inline-flex h-10 w-20 items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground ring-offset-background transition-colors hover:bg-primary/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
47-
href="/sign-in"
47+
href="/signin"
4848
>
4949
{t("common.signIn")}
5050
</Link>
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
"use client"
22

3-
import { signOut } from "next-auth/react"
43
import { useTranslations } from "next-intl"
54
import { DropdownMenuItem, DropdownMenuShortcut } from "ui"
65

6+
import { onSignOut } from "@/actions/auth"
7+
78
export const LogoutMenu = () => {
89
const t = useTranslations()
9-
const onSignOut = () => {
10-
signOut({
11-
callbackUrl: "/",
12-
})
13-
}
1410

1511
return (
16-
<DropdownMenuItem onClick={onSignOut}>
17-
{t("common.signOut")}
18-
<DropdownMenuShortcut>⇧⌘Q</DropdownMenuShortcut>
19-
</DropdownMenuItem>
12+
<form action={onSignOut}>
13+
<button
14+
type="submit"
15+
className="w-full"
16+
>
17+
<DropdownMenuItem className="hover:cursor-pointer">
18+
{t("common.signOut")}
19+
<DropdownMenuShortcut>⇧⌘Q</DropdownMenuShortcut>
20+
</DropdownMenuItem>
21+
</button>
22+
</form>
2023
)
2124
}

apps/web/app/[lang]/(auth)/signup/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const RegisterPage: React.FC = () => {
6464
</div>
6565

6666
<div className="mt-4 text-center">
67-
<Link href="sign-in">
67+
<Link href="signin">
6868
<Typography
6969
variant="span"
7070
className="mt-4"

apps/web/app/[lang]/(protected)/user/posts/page.tsx

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,29 @@ import React from "react"
22
import { Metadata } from "next/types"
33

44
import { auth } from "configs/auth"
5-
import { getPosts } from "database"
5+
import { getUser } from "database"
66

7-
import NoItemFounded from "@/molecules/no-item-founded"
87
import PageTitle from "@/molecules/page-title"
9-
import Filter from "@/molecules/user/posts/filter"
10-
import PostItem from "@/molecules/user/posts/post-item"
118

129
export async function generateMetadata(): Promise<Metadata> {
10+
const session = await auth()
11+
const user = await getUser({ userId: session?.user?.id })
12+
1313
return {
14-
title: "Posts",
15-
description: "User posts",
14+
title: `Posts - ${user?.data?.name}`,
15+
description: `Posts of ${user?.data?.name}`,
1616
}
1717
}
1818

1919
export default async function Page({ searchParams }) {
2020
const session = await auth()
21-
const { total, data } = await getPosts({
22-
searchParams: {
23-
authorId: session?.user?.id,
24-
...searchParams,
25-
},
26-
})
2721

2822
return (
2923
<div>
3024
<PageTitle title="Posts" />
3125

32-
<Filter total={total} />
33-
3426
<div className="mt-12">
35-
{data?.data?.length === 0 ? (
36-
<NoItemFounded />
37-
) : (
38-
data?.data?.map((post) => (
39-
<PostItem
40-
key={post.id}
41-
{...post}
42-
/>
43-
))
44-
)}
27+
<div>TOTO</div>
4528
</div>
4629
</div>
4730
)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { handlers } from "configs/auth"
1+
import { GET, POST } from "configs/auth"
22

3-
export { handlers as GET, handlers as POST }
3+
export { GET, POST }

apps/web/configs/auth.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import NextAuth from "next-auth"
44
import Credentials from "next-auth/providers/credentials"
55
import GithubProvider from "next-auth/providers/github"
66

7-
export const { handlers, auth, signIn, signOut } = NextAuth({
7+
export const {
8+
handlers: { GET, POST },
9+
auth,
10+
signIn,
11+
signOut,
12+
} = NextAuth({
813
adapter: PrismaAdapter(prisma),
914
providers: [
1015
GithubProvider({
@@ -17,8 +22,6 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
1722
password: {},
1823
},
1924
authorize: async (credentials: Record<string, string>) => {
20-
console.log(">>>>>", credentials)
21-
2225
try {
2326
const user = await prisma.user.findUnique({
2427
where: {
@@ -39,7 +42,7 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
3942
}),
4043
],
4144
pages: {
42-
signIn: "/sign-in",
45+
signIn: "/signin",
4346
},
4447
session: {
4548
strategy: "jwt",

apps/web/middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export async function middleware(req: NextRequest) {
1717
if (!session?.user?.email && currentPathname.startsWith("/user")) {
1818
const newUrl = req.nextUrl.clone()
1919
const currentSearchParam = newUrl.searchParams.toString()
20-
newUrl.pathname = "/sign-in"
20+
newUrl.pathname = "/signin"
2121
newUrl.searchParams.set(
2222
"callbackUrl",
2323
encodeURIComponent(`${currentPathname}?${currentSearchParam}`)

0 commit comments

Comments
 (0)