Skip to content

Commit

Permalink
Merge pull request #94 from Kusitms-29th-ASAP/fix/#93
Browse files Browse the repository at this point in the history
[Fix] 로그인 에러 해결
  • Loading branch information
yyypearl authored May 23, 2024
2 parents 833d480 + 76be2c9 commit e1009e9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/apis/auth/postKakaoToken.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Axios from "../axios";
import axios from "axios";

interface PostKakaoTokenResponse {
accessToken?: string;
Expand All @@ -10,8 +10,8 @@ export async function postKakaoToken(
accessToken: string
): Promise<PostKakaoTokenResponse> {
try {
const response = await Axios.post<PostKakaoTokenResponse>(
"/api/v1/auth/login/KAKAO",
const response = await axios.post<PostKakaoTokenResponse>(
"https://api.ncp.simproject.kr/api/v1/auth/login/KAKAO",
{
accessToken: accessToken,
}
Expand Down
10 changes: 2 additions & 8 deletions src/apis/axios.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import axios from "axios";

const getToken = () => {
if (typeof window !== "undefined") {
console.log("token", localStorage.getItem("access_token"))
return localStorage.getItem("access_token");
}
return null;
};
const accessToken = localStorage.getItem("access_token");

const Axios = axios.create({
baseURL: process.env.NEXT_PUBLIC_BASE_URL,
headers: {
Authorization: `Bearer ${getToken()}`,
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json;charset=UTF-8",
},
});
Expand Down
6 changes: 4 additions & 2 deletions src/apis/school/getShcool.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { School } from "@/interface/School";
import Axios from "../axios";
import axios from "axios";

interface GetSchoolResponse {
schools: School[];
}

export async function getSchool(keyword: string): Promise<GetSchoolResponse> {
const response = await Axios.get(`/api/v1/schools?keyword=${keyword}`);
const response = await axios.get(
`https://api.ncp.simproject.kr/api/v1/schools?keyword=${keyword}`
);
return response.data;
}

Expand Down
7 changes: 5 additions & 2 deletions src/apis/user/postUser.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { PostUserRequest, TokenResponse } from "@/interface/Auth";
import Axios from "../axios";
import axios from "axios";

export async function postUser(user: PostUserRequest): Promise<TokenResponse> {
try {
const response = await Axios.post<TokenResponse>("/api/v1/users", user);
const response = await axios.post<TokenResponse>(
"https://api.ncp.simproject.kr/api/v1/users",
user
);
return response.data;
} catch (error) {
throw new Error("Failed to register user: " + error);
Expand Down
2 changes: 0 additions & 2 deletions src/app/auth/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ const Auth = () => {
);

const kakao_accessToken = response.data.access_token;
localStorage.setItem("access_token", kakao_accessToken);

const data = await postKakaoToken(kakao_accessToken);

if (data.accessToken) {
Expand Down
13 changes: 11 additions & 2 deletions src/app/signin/process4/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ProgressBar from "@/components/signin/ProgressBar";
import Subtitle from "@/components/signin/Subtitle";
import { AllergyCategories, AllergyEnum } from "@/data/allergyData";
import { PostUserRequest } from "@/interface/Auth";
import { setToken } from "@/redux/slices/authSlice";
import { setUser } from "@/redux/slices/userSlice";
import { RootState } from "@/redux/store";
import { useRouter } from "next/navigation";
Expand All @@ -32,7 +33,7 @@ const SigninProcess4 = () => {
setCheckedItems((prev) => ({ ...prev, [item]: !prev[item] }));
};

const handleNextButtonClick = () => {
const handleNextButtonClick = async () => {
const updateChildren = user.children.map((child) => ({
...child,
allergies: Object.keys(checkedItems)
Expand All @@ -54,7 +55,15 @@ const SigninProcess4 = () => {
children: updateChildren,
};

const data = postUser(User);
const data = await postUser(User);
localStorage.setItem("access_token", data.accessToken);

dispatch(
setToken({
accessToken: data.accessToken,
refreshToken: data.refreshToken,
})
);

router.push("/signin/completion");
};
Expand Down

0 comments on commit e1009e9

Please sign in to comment.