Skip to content

Commit 77c6fbb

Browse files
committed
feat: upgrade auth.js
1 parent e8eed5e commit 77c6fbb

File tree

21 files changed

+2639
-2548
lines changed

21 files changed

+2639
-2548
lines changed

apps/web/@/actions/protect/postAction.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { toast } from "react-toastify"
1616

1717
import APP_ROUTES from "@/constants/routes"
1818
import { TUserItem, userSelect } from "@/types/users"
19-
import { getServerSession } from "@/utils/auth"
19+
import { auth } from "configs/auth"
2020

2121
// TODO: move to database package
2222
// Get total actions (like, bookmark) for a post
@@ -27,7 +27,7 @@ export const getTotalActions = async ({
2727
postId: string
2828
actionType: PostOnUserType
2929
}) => {
30-
const session = await getServerSession()
30+
const session = await auth()
3131

3232
try {
3333
const promises = []
@@ -70,7 +70,7 @@ export const addRelation = async ({
7070
postSlug: string
7171
action: PostOnUserType
7272
}) => {
73-
const session = await getServerSession()
73+
const session = await auth()
7474
const postField = action === PostOnUserType.LIKE ? "totalLike" : "totalFollow"
7575
try {
7676
await prisma.$transaction([
@@ -118,7 +118,7 @@ export const removeRelation = async ({
118118
postSlug: string
119119
action: PostOnUserType
120120
}) => {
121-
const session = await getServerSession()
121+
const session = await auth()
122122
const postField = action === PostOnUserType.LIKE ? "totalLike" : "totalFollow"
123123

124124
try {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { Edit } from "lucide-react"
44
import { getTranslations } from "next-intl/server"
55
import { buttonVariants, cn } from "ui"
66

7-
import { getServerSession } from "@/utils/auth"
7+
import { auth } from "configs/auth"
88

99
import { UserNav } from "../user-nav"
1010
import Logo from "./logo"
1111
import SearchBar from "./search-bar"
1212
import ThemeToggle from "./theme-toggle"
1313

1414
export default async function Nav() {
15-
const session = await getServerSession()
15+
const session = await auth()
1616
const t = await getTranslations()
1717

1818
return (

apps/web/@/molecules/posts/post-detail/edit-post-button/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Button, buttonVariants, cn, toast } from "ui"
1010
import { onTogglePost } from "@/actions/protect/postAction"
1111
import APP_ROUTES from "@/constants/routes"
1212
import { TPostItem } from "@/types/posts"
13-
import { getServerSession } from "@/utils/auth"
13+
import { auth } from "configs/auth"
1414

1515
import TogglePost from "./toggle-post"
1616

@@ -19,7 +19,7 @@ interface EditPostButtonProps {
1919
}
2020

2121
const EditPostButton: React.FC<EditPostButtonProps> = async ({ post }) => {
22-
const session = await getServerSession()
22+
const session = await auth()
2323
const t = await getTranslations()
2424

2525
if (post?.author?.id !== session?.user?.id) {

apps/web/@/molecules/sign-in-form/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import Link from "next/link"
44
import { useSearchParams } from "next/navigation"
55

6-
import { Label } from "@radix-ui/react-dropdown-menu"
7-
import { GithubIcon } from "lucide-react"
6+
import { Github } from "lucide-react"
87
import { signIn } from "next-auth/react"
98
import {
109
Button,
1110
Card,
1211
CardContent,
1312
CardFooter,
1413
Input,
14+
Label,
1515
Tabs,
1616
TabsContent,
1717
TabsList,
@@ -116,7 +116,7 @@ export default function SignInForm() {
116116
type="button"
117117
onClick={onSignIn}
118118
>
119-
<GithubIcon size={16} />
119+
<Github size={16} />
120120
<span className="ml-2">GitHub</span>
121121
</Button>
122122
</div>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Link from "next/link"
22

3-
import { authConfigs } from "configs/auth"
3+
import { auth, authConfigs } from "configs/auth"
44
import { getServerSession } from "next-auth"
55
import { getTranslations } from "next-intl/server"
66
import {
@@ -22,7 +22,7 @@ import {
2222
import { LogoutMenu } from "./LogoutMenu"
2323

2424
export async function UserNav() {
25-
const session = await getServerSession(authConfigs)
25+
const session = await auth()
2626
const t = await getTranslations()
2727

2828
return (

apps/web/@/utils/auth.ts

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

apps/web/app/[lang]/(auth)/sign-in/page.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import React from "react"
22
import { redirect } from "next/navigation"
33

4-
import { authConfigs } from "configs/auth"
5-
import { getServerSession } from "next-auth"
4+
import { auth } from "configs/auth"
65

76
import SignInForm from "@/molecules/sign-in-form"
87

98
export default async function Page() {
10-
const session = await getServerSession(authConfigs)
11-
9+
const session = await auth()
1210
if (session) {
1311
redirect("/")
1412
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import NoItemFounded from "@/molecules/no-item-founded"
77
import PageTitle from "@/molecules/page-title"
88
import Filter from "@/molecules/user/posts/filter"
99
import PostItem from "@/molecules/user/posts/post-item"
10-
import { getServerSession } from "@/utils/auth"
10+
import { auth } from "configs/auth"
1111

1212
export async function generateMetadata(): Promise<Metadata> {
1313
return {
@@ -17,7 +17,7 @@ export async function generateMetadata(): Promise<Metadata> {
1717
}
1818

1919
export default async function Page({ searchParams }) {
20-
const session = await getServerSession()
20+
const session = await auth()
2121
const { total, data } = await getPosts({
2222
searchParams: {
2323
authorId: session?.user?.id,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import APP_APIS from "@/constants/apis"
22
import PageTitle from "@/molecules/page-title"
33
import Profile from "@/molecules/profile"
4-
import { getServerSession } from "@/utils/auth"
4+
import { auth } from "configs/auth"
55
import { generatePath } from "@/utils/generatePath"
66

77
export default async function Page() {
88
let currentUser = null
99
try {
10-
const session = await getServerSession()
10+
const session = await auth()
1111

1212
const userRaw = await fetch(
1313
`${process.env.NEXT_PUBLIC_FRONTEND_URL}${generatePath(APP_APIS.protected.user.GET, {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { redirect } from "next/navigation"
22

33
import APP_ROUTES from "@/constants/routes"
44
import PostForm from "@/molecules/post-form"
5-
import { getServerSession } from "@/utils/auth"
5+
import { auth } from "configs/auth"
66

77
export const metadata = {
88
title: "Create Post",
99
description: "Create a new post",
1010
}
1111

1212
export default async function Page() {
13-
const session = await getServerSession()
13+
const session = await auth()
1414

1515
if (!session) {
1616
redirect(APP_ROUTES.LOGIN)

0 commit comments

Comments
 (0)