fix(auth): allow admins to create accounts when sign-ups are disabled

- Clarify that disabling self-registration still allows admin-created accounts
This commit is contained in:
joshuafhiggins committed 2026-10-09 12:12:04 -04:00 Verified
1 parent 273d29486d
commit b890de2ad1
3 files changed
+31 -19

No files matched your search

@@ -462,7 +462,7 @@ function UsersSection({
<SettingsCard title="Sign Up">
<SwitchRow
title="Disable account creation"
subtitle="Prevent new users from creating accounts."
subtitle="Stop people from registering themselves. Admins can still create accounts from the web app."
value={appSettings?.disableAccountCreation ?? false}
onValueChange={(checked) =>
void setDisableCreation({ disabled: checked }).catch(
+9 -3
View File
@@ -848,9 +848,15 @@ function UsersSection({
.catch((error: Error) => toast.error(error.message))
}}
/>
<Label htmlFor="disable-signups" className="font-normal">
Disable account creation
</Label>
<div className="space-y-1">
<Label htmlFor="disable-signups" className="font-normal">
Disable account creation
</Label>
<p className="text-sm text-muted-foreground">
Stops people from registering themselves. You can still create
accounts.
</p>
</div>
</div>
<Button type="button" size="sm" onClick={() => setCreateOpen(true)}>
<UserPlus />
+21 -15
View File
@@ -21,22 +21,28 @@ export const { auth, signIn, signOut, store, isAuthenticated } = convexAuth({
if (existingUserId === null) {
const settings = await db.query("appSettings").first()
if (settings?.disableAccountCreation) {
const sessions = await db
.query("authSessions")
.withIndex("userId", (q) => q.eq("userId", userId))
.collect()
for (const session of sessions) {
await db.delete(session._id)
// Self-service sign-up has no admin session. Accounts created from
// the admin tools run as that admin, so they stay allowed.
const actorId = await getAuthUserId(ctx)
const actor = actorId === null ? null : await db.get(actorId)
if (!actor?.isAdmin) {
const sessions = await db
.query("authSessions")
.withIndex("userId", (q) => q.eq("userId", userId))
.collect()
for (const session of sessions) {
await db.delete(session._id)
}
const accounts = await db
.query("authAccounts")
.withIndex("userIdAndProvider", (q) => q.eq("userId", userId))
.collect()
for (const account of accounts) {
await db.delete(account._id)
}
await db.delete(userId)
throw new ConvexError("Account creation is currently disabled")
}
const accounts = await db
.query("authAccounts")
.withIndex("userIdAndProvider", (q) => q.eq("userId", userId))
.collect()
for (const account of accounts) {
await db.delete(account._id)
}
await db.delete(userId)
throw new ConvexError("Account creation is currently disabled")
}
const users = await db.query("users").take(2)