Skip to content

Commit

Permalink
fix: build error
Browse files Browse the repository at this point in the history
  • Loading branch information
jiohjung98 committed Aug 19, 2024
1 parent da53ca7 commit e3cb858
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
45 changes: 25 additions & 20 deletions src/app/signup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,42 @@ const SignupPage: React.FC = () => {
loginType: 'local',
});


const handleNext = () => {
console.log('Moving to next step, current formData:', formData);
setCurrentStep((prev) => prev + 1);
};

const handleUpdate = (data: Partial<typeof formData>) => {
setFormData((prev) => ({ ...prev, ...data }));
};

useEffect(() =>
console.log(formData)
,[formData])
useEffect(() => {
console.log(formData);
}, [formData]);

const handleSubmit = async () => {
try {
console.log('최종 제출 데이터:', formData);

const accessToken = localStorage.getItem('acess_token');
if (!accessToken) {
throw new Error('Access token이 없습니다.');
}
// 클라이언트 사이드에서만 localStorage 접근
if (typeof window !== 'undefined') {
const accessToken = localStorage.getItem('access_token');
if (!accessToken) {
throw new Error('Access token이 없습니다.');
}

const authHeaders = {
cookie: '',
authorization: `Bearer ${accessToken}`,
};

const authHeaders = {
cookie: '',
authorization: `Bearer ${accessToken}`,
};
const response = await finalSignup(formData, authHeaders);
console.log('서버 응답 데이터:', response);

} else {
console.error('클라이언트 사이드에서만 실행되어야 합니다.');
}

const response = await finalSignup(formData, authHeaders);
console.log('서버 응답 데이터:', response);

} catch (error) {
console.error('서버 요청 오류:', error);
}
Expand All @@ -81,10 +86,10 @@ const SignupPage: React.FC = () => {
/>
)}
{currentStep === 4 && (
<Step4
onNext={handleSubmit}
onUpdate={(data) => handleUpdate(data)}
/>
<Step4
onNext={handleSubmit}
onUpdate={(data) => handleUpdate(data)}
/>
)}
</div>
);
Expand Down
18 changes: 15 additions & 3 deletions src/service/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ export const verifyCode = async (phone: string, code: string): Promise<VerifyCod
console.log('토큰', token);
const accessToken = token.replace('Bearer ', '');
console.log('어세스토큰', accessToken);
localStorage.setItem('access_token', accessToken);

if (typeof window !== 'undefined') {
localStorage.setItem('access_token', accessToken);
} else {
console.error('클라이언트 사이드에서만 localStorage를 사용할 수 있습니다.');
}

return response.data;
};

Expand Down Expand Up @@ -84,10 +90,16 @@ export const login = async (email: string, password: string) => {
console.log('토큰', token);
const accessToken = token.replace('Bearer ', '');
console.log('어세스토큰', accessToken);
localStorage.setItem('access_token', accessToken);

if (typeof window !== 'undefined') {
localStorage.setItem('access_token', accessToken);
} else {
console.error('클라이언트 사이드에서만 localStorage를 사용할 수 있습니다.');
}

return response.data;
} catch (error) {
console.error('로그인 오류:', error);
throw error;
}
};
};
2 changes: 1 addition & 1 deletion src/store/userAuth.store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import create from 'zustand';
import { create } from 'zustand';

interface AuthState {
isLoggedIn: boolean;
Expand Down

0 comments on commit e3cb858

Please sign in to comment.