-
Notifications
You must be signed in to change notification settings - Fork 3
feat: 프로필 설정 로그아웃/팀 탈퇴 기능 추가 (#63) #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,53 @@ | ||
| 'use server'; | ||
|
|
||
| import { revalidatePath } from 'next/cache'; | ||
| import { z } from 'zod'; | ||
| import { getCurrentUserId } from '@/shared/api/supabase/current-user'; | ||
| import { createSupabaseServerClient } from '@/shared/api/supabase/server'; | ||
|
|
||
| const leaveWorkspaceInputSchema = z.object({ | ||
| workspaceId: z.guid(), | ||
| }); | ||
|
|
||
| export type LeaveWorkspaceInput = z.infer<typeof leaveWorkspaceInputSchema>; | ||
|
|
||
| export async function leaveWorkspace(input: LeaveWorkspaceInput): Promise<void> { | ||
| const parsed = leaveWorkspaceInputSchema.safeParse(input); | ||
| if (!parsed.success) { | ||
| throw new Error('입력값이 올바르지 않습니다'); | ||
| } | ||
|
|
||
| const userId = await getCurrentUserId(); | ||
| const supabase = await createSupabaseServerClient(); | ||
|
|
||
| // role 조건을 DELETE 자체에 걸어 확인과 삭제를 한 번에 처리한다(owner는 매칭되지 않아 삭제되지 않음). | ||
| const { data: deleted, error } = await supabase | ||
| .from('workspace_members') | ||
| .delete() | ||
| .eq('workspace_id', parsed.data.workspaceId) | ||
| .eq('user_id', userId) | ||
| .eq('role', 'member') | ||
| .select('user_id'); | ||
|
|
||
| if (error) { | ||
| throw new Error('팀 탈퇴에 실패했어요. 잠시 후 다시 시도해주세요.'); | ||
| } | ||
|
|
||
| if (!deleted || deleted.length === 0) { | ||
| const { data: member } = await supabase | ||
| .from('workspace_members') | ||
| .select('role') | ||
| .eq('workspace_id', parsed.data.workspaceId) | ||
| .eq('user_id', userId) | ||
| .maybeSingle(); | ||
|
|
||
| if (member?.role === 'owner') { | ||
| throw new Error( | ||
| '워크스페이스 소유자는 팀을 탈퇴할 수 없어요. 소유권을 이전한 후 탈퇴해주세요.', | ||
| ); | ||
| } | ||
| throw new Error('멤버 정보를 찾을 수 없어요'); | ||
| } | ||
|
|
||
| revalidatePath('/workspaces'); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,14 @@ | ||
| import { createClient } from '@/shared/lib/client'; | ||
|
|
||
| export function useLogout() { | ||
| const handleLogout = async () => { | ||
| try { | ||
| const supabase = createClient(); | ||
| await supabase.auth.signOut(); | ||
| } finally { | ||
| window.location.href = '/login'; | ||
| } | ||
| }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| return { handleLogout }; | ||
| } | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
현재 구현은 일반 멤버만 멤버십 행을 하드 삭제하고, 소유자는 삭제 대상에서 제외한 뒤 소유권 이전 안내를 반환하므로 요구사항에 맞는 것으로 보입니다