Skip to content

Commit ae4cd7c

Browse files
committed
chore: 로그인 요청에 provider 정보를 포함
1 parent aaf2f9a commit ae4cd7c

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

src/app/(auth)/signup/applicant/page.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,16 @@ export default function ApplicantSignupPage() {
108108
</div>
109109
<div className="flex justify-center space-x-4">
110110
<Link
111-
href={`https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile&response_type=code&redirect_uri=${process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URI}&client_id=${process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID}&state=${encodeURIComponent("applicant")}`}
111+
href={`https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile&response_type=code&redirect_uri=${process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URI}&client_id=${process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID}&state=${encodeURIComponent(
112+
JSON.stringify({ provider: "google", role: "applicant" })
113+
)}`}
112114
>
113115
<Image src="/icons/social/social_google.svg" width={72} height={72} alt="구글 로그인" />
114116
</Link>
115117
<Link
116-
href={`https://kauth.kakao.com/oauth/authorize?client_id=${process.env.NEXT_PUBLIC_KAKAO_REST_API_KEY}&redirect_uri=${process.env.NEXT_PUBLIC_KAKAO_REDIRECT_URI}&response_type=code&state=${encodeURIComponent("applicant")}`}
118+
href={`https://kauth.kakao.com/oauth/authorize?client_id=${process.env.NEXT_PUBLIC_KAKAO_REST_API_KEY}&redirect_uri=${process.env.NEXT_PUBLIC_KAKAO_REDIRECT_URI}&response_type=code&state=${encodeURIComponent(
119+
JSON.stringify({ provider: "kakao", role: "applicant" })
120+
)}`}
117121
>
118122
<Image src="/icons/social/social_kakao.svg" width={72} height={72} alt="카카오 로그인" />
119123
</Link>

src/app/(auth)/signup/owner/page.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,16 @@ export default function OwnerSignupPage() {
130130
</div>
131131
<div className="flex justify-center space-x-4">
132132
<Link
133-
href={`https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile&response_type=code&redirect_uri=${process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URI}&client_id=${process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID}&state=${encodeURIComponent("owner")}`}
133+
href={`https://accounts.google.com/o/oauth2/v2/auth?scope=https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile&response_type=code&redirect_uri=${process.env.NEXT_PUBLIC_GOOGLE_REDIRECT_URI}&client_id=${process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID}&state=${encodeURIComponent(
134+
JSON.stringify({ provider: "google", role: "owner" })
135+
)}`}
134136
>
135137
<Image src="/icons/social/social_google.svg" width={72} height={72} alt="구글 로그인" />
136138
</Link>
137139
<Link
138-
href={`https://kauth.kakao.com/oauth/authorize?client_id=${process.env.NEXT_PUBLIC_KAKAO_REST_API_KEY}&redirect_uri=${process.env.NEXT_PUBLIC_KAKAO_REDIRECT_URI}&response_type=code&state=${encodeURIComponent("owner")}`}
140+
href={`https://kauth.kakao.com/oauth/authorize?client_id=${process.env.NEXT_PUBLIC_KAKAO_REST_API_KEY}&redirect_uri=${process.env.NEXT_PUBLIC_KAKAO_REDIRECT_URI}&response_type=code&state=${encodeURIComponent(
141+
JSON.stringify({ provider: "kakao", role: "owner" })
142+
)}`}
139143
>
140144
<Image src="/icons/social/social_kakao.svg" width={72} height={72} alt="카카오 로그인" />
141145
</Link>

src/app/api/oauth/callback/google/route.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { NextRequest, NextResponse } from "next/server";
22
import axios from "axios";
33
import { decodeJwt } from "@/middleware";
4+
import { OauthUser } from "@/types/oauth/oauthReq";
5+
46
export const GET = async (req: NextRequest) => {
57
const searchParams = req.nextUrl.searchParams;
68
const code = searchParams.get("code");
@@ -41,19 +43,16 @@ export const GET = async (req: NextRequest) => {
4143
return NextResponse.json({ message: "Invalid ID token" }, { status: 400 });
4244
}
4345

44-
const user = {
45-
id: decodedIdToken.sub,
46+
const googleUser: OauthUser = {
47+
role: role || "",
4648
name: decodedIdToken.name,
47-
role: role,
48-
picture: decodedIdToken.picture,
49-
email: decodedIdToken.email,
49+
token: id_token,
5050
};
51-
console.log("Google user:", user);
52-
// 여기서 role이 "role":"\bowner"로 나옴
51+
console.log("Google user:", googleUser);
5352

5453
// 사용자 정보를 클라이언트에 반환
5554
const response = NextResponse.redirect("http://localhost:3000");
56-
response.cookies.set("user", JSON.stringify(user), {
55+
response.cookies.set("user", JSON.stringify(googleUser), {
5756
httpOnly: true,
5857
secure: process.env.NODE_ENV === "production",
5958
sameSite: "strict",

0 commit comments

Comments
 (0)