Skip to content

Commit 4b42333

Browse files
committed
refactor: add a shared authentication header object
1 parent 9b617c6 commit 4b42333

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

apps/web/src/app/auth/callback/page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import Image from "next/image";
44
import { useRouter } from "next/navigation";
55
import { useEffect, useState } from "react";
6+
import { authHeaders } from "@/config/header";
67
import { client } from "@/lib/client";
78

89
export default function AuthCallback() {
@@ -12,7 +13,7 @@ export default function AuthCallback() {
1213
const [userInfo, setUserInfo] = useState<{
1314
id: string;
1415
email: string;
15-
username: string;
16+
name: string;
1617
avatar_url?: string;
1718
} | null>(null);
1819

@@ -47,8 +48,7 @@ export default function AuthCallback() {
4748
},
4849
{
4950
headers: {
50-
"Content-Type": "application/json",
51-
credentials: "include",
51+
...authHeaders,
5252
},
5353
}
5454
);
@@ -134,7 +134,7 @@ export default function AuthCallback() {
134134
/>
135135
)}
136136
<div className="text-left">
137-
<p className="text-sm font-medium text-gray-900">{userInfo.username}</p>
137+
<p className="text-sm font-medium text-gray-900">{userInfo.name}</p>
138138
<p className="text-sm text-gray-500">{userInfo.email}</p>
139139
</div>
140140
</div>

apps/web/src/app/auth/login/page.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import Image from "next/image";
44
import { useRouter } from "next/navigation";
55
import { useEffect, useState } from "react";
6+
import { authHeaders } from "@/config/header";
67
import { SIGN_IN_LINK } from "@/config/link";
7-
import { env } from "@/env";
88
import { client } from "@/lib/client";
99

1010
interface UserInfo {
1111
id: string;
1212
email: string;
13-
username: string;
13+
name: string;
1414
avatar_url?: string;
1515
}
1616

@@ -39,9 +39,7 @@ export default function TestPage() {
3939
.post(
4040
{},
4141
{
42-
headers: {
43-
credentials: "include",
44-
},
42+
...authHeaders,
4543
}
4644
)
4745
.catch((error) => {
@@ -67,7 +65,7 @@ export default function TestPage() {
6765
/>
6866
)}
6967
<div className="text-left">
70-
<h3 className="text-lg font-medium text-gray-900">{user.username}</h3>
68+
<h3 className="text-lg font-medium text-gray-900">{user.name}</h3>
7169
<p className="text-sm text-gray-500">{user.email}</p>
7270
<p className="text-xs text-gray-400 mt-1">ID: {user.id}</p>
7371
</div>

apps/web/src/config/header.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const authHeaders: Record<string, string> = {
2+
credentials: "include",
3+
};

0 commit comments

Comments
 (0)