Skip to content

Comments

Feature/#294 user 관련 supabase api 추가#192

Open
SwimmingRiver wants to merge 7 commits intodevelopfrom
feature/#294-user-supabase
Open

Feature/#294 user 관련 supabase api 추가#192
SwimmingRiver wants to merge 7 commits intodevelopfrom
feature/#294-user-supabase

Conversation

@SwimmingRiver
Copy link
Collaborator

변경 사항

  • user 관련 api supabase 버전으로 추가했습니다.

구현결과(사진첨부 선택)

  • user 생성시에 supabase user 테이블에 저장됩니다.
  • 로그인시에는 supabase에서 제공하는 서비스로 토큰을 받을 수 있습니다.
  • 유저정보 가져오기는 supabase에서 발급해주는 jwt로 access_token을 받아와서 기존 방식에 적용했습니다.
  • 로그아웃 supabase로 변경했습니다.

변경해야할 부분이 많아서 대공사가 될거 같은데 병합을 하는게 맞을 지 조금 고민이 됩니다.
의견 편하게 말씀해주세요!!

@netlify
Copy link

netlify bot commented Jul 24, 2025

Deploy Preview for we-write failed.

Name Link
🔨 Latest commit 9dbe123
🔍 Latest deploy log https://app.netlify.com/projects/we-write/deploys/68882be1591a8a00072fac73

Copy link
Collaborator

@juyesu juyesu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

방향성 자체는 굉장히 좋은 것 같습니다! 병합 이전에 추가로 작업해야 하는 내용이 많을까요? 아니면 별도의 브랜치로 진행하실 예정일까요?

Comment on lines +30 to +32
if (!data) {
throw new Error('User not found');
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

에러 처리 로직을 위해서 명헌님께서 개발해주신 handleError() 공통 함수를 사용해주셔도 좋을 것 같습니다

value={{
isSignIn,
myInfo,
userInfo,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반환하는 데이터의 네이밍이 myInfo, userInfo라서 차이를 구분하기 어려울 것 같은데, 명확한 네이밍으로 변경해주시면 좋을 것 같아요!

}: AuthProviderClientProps) => {
const { data: myInfo, ...rest } = useGetMyInfo(accessToken ?? '');
const { data: userInfo } = useQuery<UserInfoResponse | null>({
queryKey: ['userInfo'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

queryKey.ts에 상수화시켜놓은 다른 쿼리 키들처럼 해당 키도 상수로 사용하면 좋을 것 같습니다

isSignIn,
}: AuthProviderClientProps) => {
const { data: myInfo, ...rest } = useGetMyInfo(accessToken ?? '');
const { data: userInfo } = useQuery<UserInfoResponse | null>({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

타입 추론 에러가 발생해서 제네릭을 사용해주신 걸까요?

Comment on lines +27 to +71
if (error) {
throw new Error(error.message);
}
return data;
};

export const signin = async (user: SigninRequest) => {
const { data, error } = await instanceBaaS.auth.signInWithPassword({
email: user.email,
password: user.password,
});
if (error) {
throw new Error(error.message);
}
const cookieStore = await cookies();
cookieStore.set('access_token', data.session.access_token);
cookieStore.set('refresh_token', data.session.refresh_token);
return data;
};

export const signout = async () => {
const cookieStore = await cookies();
cookieStore.delete('access_token');
cookieStore.delete('refresh_token');
};

export const getUserInfo = async (): Promise<UserInfoResponse | null> => {
const cookieStore = await cookies();
const accessToken = cookieStore.get('access_token');
const refreshToken = cookieStore.get('refresh_token');
if (!accessToken || !refreshToken) {
return null;
}
const { data, error } = await instanceBaaS.auth.getUser(accessToken.value);
const { data: user, error: userError } = await instanceBaaS
.from('users')
.select('*')
.eq('email', data.user?.email ?? '')
.single();
if (error) {
throw new Error(error.message);
}
if (userError) {
throw new Error(userError.message);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이부분들도 변경된 에러 처리 방식을 적용해주시면 감사하겠습니다!

Comment on lines +212 to +244
users: {
Row: {
created_at: string;
email: string;
favorite: string;
id: number;
image: string | null;
last_seen_at: string | null;
name: string;
updated_at: string | null;
};
Insert: {
created_at?: string;
email: string;
favorite: string;
id?: number;
image?: string | null;
last_seen_at?: string | null;
name: string;
updated_at?: string | null;
};
Update: {
created_at?: string;
email?: string;
favorite?: string;
id?: number;
image?: string | null;
last_seen_at?: string | null;
name?: string;
updated_at?: string | null;
};
Relationships: [];
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npx supabase gen types typescript ... 명령어로 CLI 자동 타입 생성을 사용해주신건가요?

Comment on lines +47 to +51
export const signout = async () => {
const cookieStore = await cookies();
cookieStore.delete('access_token');
cookieStore.delete('refresh_token');
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • usePostSignout.ts에서도 onSuccess 시에 동일하게 쿠키를 삭제하고 있는데 함수에서 이미 쿠키를 삭제한다면 커스텀 훅의 쿠키 삭제 로직은 제거하는게 좋을까요?
  • supabase 관련 로직이 존재하지 않아서 해당 함수를 lib/supabase/아래에 선언하는 것이 괜찮을지 고민되네요. usePostSignout 내부에서 바로 선언하거나, utils로 위치를 변경하는 방법도 있을 것 같은데 어떻게 생각하실까요?

password: string;
passwordCheck: string;
companyName: string;
favorite: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋아하는 작품? 창작물? 이라는 의미까지 변수명/필드명에 담기면 더욱 명시적일 것 같습니다! (favoriteWorks, favoriteCreations, favoriteContents, ... 등)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants