Skip to content
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

fix(api): soft delete user should also delete in auth table #137

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/api-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
cache: pnpm

- name: ⬆️ Install dependencies
run: pnpm -F api install
run: pnpm --color -F api install

- name: 🚀 Start Supabase
run:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
cache: pnpm

- name: ⬆️ Install dependencies
run: pnpm install
run: pnpm --color install

- name: 🚀 Run Biome
run: pnpm run lint:check
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/handlers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ auth.openapi(loginUser, async (c) => {
.single();

if (userError || !user) throw new HTTPException(404, { message: 'User not found' });
if (user.deleted_at !== null) throw new HTTPException(404, { message: 'User has been deleted' });

setCookie(c, 'access_token', data?.session.access_token, {
maxAge: 31536000, // 1 year
Expand Down
7 changes: 6 additions & 1 deletion apps/api/src/handlers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ users.openapi(softDeleteUser, async (c) => {

const { data: user_data, error: errorID } = await supabase
.from('USERS')
.select('id, deleted_at')
.select('id, deleted_at, id_auth')
.eq('id', id)
.single();

Expand All @@ -270,13 +270,18 @@ users.openapi(softDeleteUser, async (c) => {
email: `Deleted${user_data.id}`,
date_validity: null,
deleted_at: new Date().toISOString(),
id_auth: null,
})
.eq('id', id);

if (error) {
return c.json({ error: 'Failed to delete user' }, 500);
}

if (user_data?.id_auth) {
await supAdmin.auth.admin.deleteUser(user_data.id_auth);
}

return c.json({ message: 'User deleted' }, 200);
});

Expand Down
Loading