Skip to content

Commit 88729b4

Browse files
authored
Merge pull request #139 from CodeForStartup/feat/upgrade-auth.js
feat: upgrade auth.js
2 parents e8eed5e + 853504a commit 88729b4

File tree

31 files changed

+2866
-2734
lines changed

31 files changed

+2866
-2734
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use server"
2+
3+
import { signIn, signOut } from "configs/auth"
4+
5+
export const signInWithCredentials = async (email: string, password: string) => {
6+
await signIn("credentials", {
7+
email,
8+
password,
9+
})
10+
}
11+
12+
export const signInWithGithub = async () => {
13+
await signIn("github")
14+
}
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/@/actions/protect/postAction.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { revalidatePath } from "next/cache"
44
import { redirect } from "next/navigation"
55

6+
import { auth } from "configs/auth"
67
import prisma, {
78
createPost,
89
PostOnUserType,
@@ -16,7 +17,6 @@ import { toast } from "react-toastify"
1617

1718
import APP_ROUTES from "@/constants/routes"
1819
import { TUserItem, userSelect } from "@/types/users"
19-
import { getServerSession } from "@/utils/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/@/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/@/messages/en.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,5 +138,44 @@
138138
"name_asc": "Name (A → Z)",
139139
"name_desc": "Name (Z → A)"
140140
}
141+
},
142+
"auth": {
143+
"email_label": "Email",
144+
"password_label": "Password",
145+
"email_placeholder": "Enter your email",
146+
"password_placeholder": "Enter your password",
147+
"dont_have_an_account": "Don't have an account?",
148+
"or_continue_with": "Or continue with",
149+
"github": "GitHub",
150+
"google": "Google",
151+
"facebook": "Facebook",
152+
"twitter": "Twitter",
153+
"linkedin": "LinkedIn",
154+
"instagram": "Instagram",
155+
"youtube": "YouTube",
156+
"tiktok": "TikTok",
157+
"sign_in": {
158+
"title": "Sign In",
159+
"description": "Sign in to your account",
160+
"sign_in_with": "Sign in with {provider}",
161+
"sign_in_with_github": "Sign in with GitHub",
162+
"sign_in_with_google": "Sign in with Google",
163+
"sign_in_with_facebook": "Sign in with Facebook",
164+
"sign_in_with_twitter": "Sign in with Twitter",
165+
"sign_in_with_linkedin": "Sign in with LinkedIn",
166+
"sign_in_with_instagram": "Sign in with Instagram",
167+
"sign_in_with_youtube": "Sign in with YouTube",
168+
"sign_in_with_tiktok": "Sign in with TikTok"
169+
},
170+
"sign_up": {
171+
"title": "Sign Up",
172+
"description": "Sign up for an account"
173+
},
174+
"forgot_password": {
175+
"title": "Forgot Password",
176+
"description": "Forgot your password? Enter your email address and we will send you a link to reset your password.",
177+
"send_instructions": "Send Instructions",
178+
"cancel": "Cancel"
179+
}
141180
}
142181
}

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

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

3+
import { auth } from "configs/auth"
34
import { Edit } from "lucide-react"
45
import { getTranslations } from "next-intl/server"
56
import { buttonVariants, cn } from "ui"
67

7-
import { getServerSession } from "@/utils/auth"
8-
98
import { UserNav } from "../user-nav"
109
import Logo from "./logo"
1110
import SearchBar from "./search-bar"
1211
import ThemeToggle from "./theme-toggle"
1312

1413
export default async function Nav() {
15-
const session = await getServerSession()
14+
const session = await auth()
1615
const t = await getTranslations()
1716

1817
return (
@@ -45,7 +44,7 @@ export default async function Nav() {
4544
<div className="flex w-20 items-center">
4645
<Link
4746
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"
48-
href="/sign-in"
47+
href="/signin"
4948
>
5049
{t("common.signIn")}
5150
</Link>

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
@@ -1,6 +1,7 @@
11
import React from "react"
22
import Link from "next/link"
33

4+
import { auth } from "configs/auth"
45
import { PostStatus } from "database"
56
import { updatePostStatus } from "database/src/posts/queries"
67
import { LucideEdit } from "lucide-react"
@@ -10,7 +11,6 @@ import { Button, buttonVariants, cn, toast } from "ui"
1011
import { onTogglePost } from "@/actions/protect/postAction"
1112
import APP_ROUTES from "@/constants/routes"
1213
import { TPostItem } from "@/types/posts"
13-
import { getServerSession } from "@/utils/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) {

0 commit comments

Comments
 (0)