-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
355 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,32 @@ | ||
import styles from "./header.module.css"; | ||
import { FolderInfo, SampleFolder } from "../../types/types"; | ||
import Image from "next/image"; | ||
import useUserStore from "@/hooks/useStore"; | ||
|
||
interface HeaderProps { | ||
folderInfo: SampleFolder; | ||
folderName: string; | ||
} | ||
|
||
export default function Header({ folderInfo }: HeaderProps) { | ||
export default function Header({ folderName }: HeaderProps) { | ||
const { user } = useUserStore(); | ||
const name = user[0]?.name; | ||
|
||
return ( | ||
<header className={styles.header}> | ||
<div className={styles.userInfoBox}> | ||
<Image | ||
src={folderInfo?.folder.owner.profileImageSource} | ||
alt="profile" | ||
className={styles.profileImage} | ||
width={24} | ||
height={24} | ||
/> | ||
<span className={styles.userName}>{folderInfo?.folder.owner.name}</span> | ||
{user?.map((item) => ( | ||
<Image | ||
key={item.id} | ||
src={item.image_source} | ||
alt="profile" | ||
className={styles.profileImage} | ||
width={24} | ||
height={24} | ||
/> | ||
))} | ||
|
||
<span className={styles.userName}>{name}</span> | ||
</div> | ||
<span className={styles.folderName}>{folderInfo?.folder.name}</span> | ||
<span className={styles.folderName}>{folderName}</span> | ||
</header> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { SIGNIN_ENDPOINT, instance } from "@/api/services/config"; | ||
import { FormValues } from "@/components/signinForm/SigninForm"; | ||
import { setAccessToken } from "@/utils/localStorage"; | ||
import { useRouter } from "next/router"; | ||
import { ReactNode, createContext, useContext, useState } from "react"; | ||
|
||
interface AuthProviderProps { | ||
children: ReactNode; | ||
} | ||
|
||
const AuthContext = createContext({ | ||
signin: async (data: FormValues) => {}, | ||
}); | ||
|
||
export function AuthProvider({ children }: AuthProviderProps) { | ||
const router = useRouter(); | ||
|
||
const signin = async (data: FormValues) => { | ||
let res; | ||
try { | ||
res = await instance.post(`${SIGNIN_ENDPOINT}`, { | ||
email: data.email, | ||
password: data.password, | ||
}); | ||
const accessToken = res?.data.data.accessToken; | ||
setAccessToken(accessToken); | ||
res?.status === 200 && router.push("/folder"); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; | ||
return ( | ||
<AuthContext.Provider | ||
value={{ | ||
signin, | ||
}} | ||
> | ||
{children} | ||
</AuthContext.Provider> | ||
); | ||
} | ||
|
||
export const useAuth = () => { | ||
const context = useContext(AuthContext); | ||
if (!context) { | ||
throw new Error("반드시 AuthProvider 안에서 사용해야 합니다."); | ||
} | ||
|
||
return context; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { User } from "@/types/types"; | ||
import { create } from "zustand"; | ||
import { persist } from "zustand/middleware"; | ||
|
||
interface UserState { | ||
user: User[]; | ||
setUser: (payload: User[]) => void; | ||
} | ||
|
||
const useUserStore = create<UserState>()( | ||
persist( | ||
(set) => ({ | ||
user: [], | ||
setUser: (payload) => set((state) => ({ user: (state.user = payload) })), | ||
}), | ||
{ | ||
name: "userData", | ||
} | ||
) | ||
); | ||
|
||
export default useUserStore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.