Skip to content

Commit

Permalink
feat: 졸업 요건 api 반영, 실제 로그인 api 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
yeolyi committed Apr 1, 2024
1 parent 8a2a911 commit b919b06
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function PdfPicker({ data }: { data: DegreeRequirements['yearList
onClick={setIndex}
/>
</div>
<Attachments files={[data[index].attachment]} />
<Attachments files={[data[index].attachments[0]]} />
</div>
);
}
2 changes: 1 addition & 1 deletion components/layout/header/HeaderRight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const AuthButton = () => {

return (
<button onClick={state === 'logout' ? login : logout} className="hover:text-main-orange">
{t(state === 'logout' ? '로그인' : '로그아웃') + '(test)'}
{t(state === 'logout' ? '로그인' : '로그아웃')}
</button>
);
};
24 changes: 18 additions & 6 deletions contexts/SessionContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';

import { useRouter } from 'next/navigation';
import React, {
createContext,
useContext,
Expand All @@ -11,6 +12,8 @@ import React, {

import { getIsStaff, getMockAuth, removeAuth } from '@/actions/session';

import { LOGIN_URL, LOGOUT_URL } from '@/constants/network';

export type UserState = 'logout' | 'non-staff' | 'staff';

type SessionContextData = {
Expand All @@ -29,6 +32,7 @@ export const useSessionContext = () => useContext(SessionContext);

export default function SessionContextProvider({ children }: PropsWithChildren) {
const [state, setState] = useState<UserState>('logout');
const router = useRouter();

const refresh = useCallback(async () => {
const resp = await getIsStaff();
Expand All @@ -40,16 +44,24 @@ export default function SessionContextProvider({ children }: PropsWithChildren)
}, [refresh]);

const login = useCallback(async () => {
// TODO: 실제 배포시 LOGIN_URL, LOGOUT_URL 사용
await getMockAuth();
if (process.env.NODE_ENV === 'development') {
await getMockAuth();
} else {
router.push(LOGIN_URL);
}

await refresh();
}, [refresh]);
}, [refresh, router]);

const logout = useCallback(async () => {
// TODO: 실제 배포시 LOGIN_URL, LOGOUT_URL 사용
removeAuth();
if (process.env.NODE_ENV === 'development') {
removeAuth();
} else {
router.push(LOGOUT_URL);
}

await refresh();
}, [refresh]);
}, [refresh, router]);

return (
<SessionContext.Provider value={{ state, login, logout }}>{children}</SessionContext.Provider>
Expand Down
4 changes: 2 additions & 2 deletions types/academics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ export interface DegreeRequirements {
description: string;
yearList: {
year: number;
attachment: {
attachments: {
name: string;
url: string;
bytes: number;
};
}[];
}[];
}

Expand Down

0 comments on commit b919b06

Please sign in to comment.