-
Notifications
You must be signed in to change notification settings - Fork 2
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
283 create api endpointserver func to delete allowed logins #345
283 create api endpointserver func to delete allowed logins #345
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
quick fix
This reverts commit d387ffc.
src/server/actions/Setting.ts
Outdated
try { | ||
dbConnect(); | ||
doc = await getSettings() | ||
} catch (error) { | ||
throw new CMError(CMErrorType.InternalError) | ||
} | ||
|
||
const index = doc.allowedEmails.indexOf(email) | ||
// No matching email found in email document | ||
if (index == -1) { | ||
throw new CMError(CMErrorType.NoSuchKey, "Email") | ||
} else { | ||
// Modifies array in-place | ||
doc.allowedEmails.splice(index, 1) | ||
// Set database obj array to modified array of retrieved document | ||
await SettingsSchema.updateOne({ _id: doc._id }, { allowedEmails: doc.allowedEmails }) | ||
|
||
// Delete associated user if one exists | ||
try { | ||
await UserSchema.findOneAndRemove({ email: email }) | ||
} catch (e) { } |
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.
why are there two try catches here?
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.
First try catch is for throwing error if database call fails. Second try-catch never throws an error, it's just necessary to delete a user with the given email if one exists and to do nothing if one doesn't exist.
Description
Added
removeAllowedEmail()
insrc/server/actions/Setting.ts
which removes an email from the allowed emails list in the settings document and deletes a user if there is a user associated with that email.Added API endpoint at DELETE
/api/settings/emails
and associated zod types to callremoveAllowedEmail()
.Relevant issue(s)
#283
Questions
Should this include authorization?
Do we want to move this to
Settings.ts
?Type of change
Checklist:
To test
Log in as an admin and hit DELETE
/api/settings/emails?email=<email to delete>
.