⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
fix: sign-in offers a deactivated account a new confirmation email (#625)
Pasqual Troncone5e897d575c60
diff --git a/apps/api/src/modules/god/__tests__/integration/god-email-verification.test.ts b/apps/api/src/modules/god/__tests__/integration/god-email-verification.test.tsindex 119fca81..e6e17588 100644--- a/apps/api/src/modules/god/__tests__/integration/god-email-verification.test.ts+++ b/apps/api/src/modules/god/__tests__/integration/god-email-verification.test.ts@@ -68,7 +68,9 @@ describe('email verification', () => {expect(res.status).toBe(200);expect(((await res.json()) as { token: string | null }).token).toBeNull();expect((await authedApi(cookieOf(res)).projects.get()).status).toBe(401);- expect((await signIn('[email protected]')).status).toBe(403);+ const refused = await signIn('[email protected]');+ expect(refused.status).toBe(403);+ expect(await refused.json()).toMatchObject({ code: 'EMAIL_NOT_VERIFIED' });expect((await api['auth-config'].get()).data).toMatchObject({requireEmailVerification: true,});diff --git a/apps/web/src/features/auth/services/auth.service.test.ts b/apps/web/src/features/auth/services/auth.service.test.tsnew file mode 100644index 00000000..4e8d3d74--- /dev/null+++ b/apps/web/src/features/auth/services/auth.service.test.ts@@ -0,0 +1,32 @@+import assert from 'node:assert/strict';+import { describe, it } from 'node:test';+import { EmailNotConfirmedError, signInError } from './auth.service';++// The sign-in form offers to send the confirmation link again only when the address is+// what stopped the sign-in. The api answers 403 for other refusals too.+describe('signInError', () => {+ it('reports an unconfirmed address', () => {+ const error = signInError({+ code: 'EMAIL_NOT_VERIFIED',+ message: 'Confirm your email address before signing in',+ });+ assert.ok(error instanceof EmailNotConfirmedError);+ });++ it('does not report a deactivated account as unconfirmed', () => {+ const error = signInError({+ code: 'ACCOUNT_DEACTIVATED',+ message: 'This account is deactivated',+ });+ assert.ok(!(error instanceof EmailNotConfirmedError));+ assert.equal(error.message, 'This account is deactivated');+ });++ it('does not report a disabled password form as unconfirmed', () => {+ const error = signInError({+ code: 'PASSWORD_AUTH_DISABLED',+ message: 'Password sign-in is disabled on this instance',+ });+ assert.ok(!(error instanceof EmailNotConfirmedError));+ });+});diff --git a/apps/web/src/features/auth/services/auth.service.ts b/apps/web/src/features/auth/services/auth.service.tsindex d713cd4f..7e5b3d1f 100644--- a/apps/web/src/features/auth/services/auth.service.ts+++ b/apps/web/src/features/auth/services/auth.service.ts@@ -16,9 +16,9 @@ const appUrl = (path: string) =>// is set and the proxy lets the user into the planner. A failure without a// message throws an empty one, and the caller (useAuthAction) words it.-// Sign-in was refused because the address is not confirmed yet. The only 403 the-// sign-in endpoint raises is the verification gate in @repo/auth, so the status is-// enough to tell it apart from wrong credentials and offer the link again.+// Sign-in was refused because the address is not confirmed yet. The verification gate+// in @repo/auth answers 403 with this code, as better-auth does; a deactivated account+// and a disabled password form are 403s too, and must not offer the link again.export class EmailNotConfirmedError extends Error {}// The sign-in screen has one field for two identifiers: an address goes to@@ -36,10 +36,14 @@ export async function signInWithPassword(input: {const result = isEmailAddress(identifier)? await signIn.email({ email: identifier, password: input.password }): await signIn.username({ username: identifier, password: input.password });- if (!result.error) return;- const message = result.error.message ?? '';- if (result.error.status === 403) throw new EmailNotConfirmedError(message);- throw new Error(message);+ if (result.error) throw signInError(result.error);+}++export function signInError(error: { message?: string; code?: string }): Error {+ const message = error.message ?? '';+ return error.code === 'EMAIL_NOT_VERIFIED'+ ? new EmailNotConfirmedError(message)+ : new Error(message);}// autoSignIn (set in @repo/auth) signs the user in right after sign-up, unless thediff --git a/packages/auth/AGENTS.md b/packages/auth/AGENTS.mdindex 1647a04b..6e9c5755 100644--- a/packages/auth/AGENTS.md+++ b/packages/auth/AGENTS.md@@ -54,7 +54,9 @@ they last.`hooks.before` gates `/sign-up/email` (closed → 403, an address outside`allowedEmailDomains` → 403, invite → no pending, unexpired invite for that address → 403)-and holds back `/sign-in/email` for an unconfirmed address while verification is required. The requirement never outlives the mail provider: the api+and holds back `/sign-in/email` for an unconfirmed address while verification is required, with 403+`EMAIL_NOT_VERIFIED`, better-auth's own code for it. The sign-in form reads that code to offer the+confirmation link again; a deactivated account and a disabled password form are 403s too. The requirement never outlives the mail provider: the apirefuses to turn it on without one, and `setEmailSettings` clears it when the provideris removed, so the setting alone is what the gate, the sign-up endpoint and thepublic `/auth-config` read — none of them checks the provider again.diff --git a/packages/auth/src/index.ts b/packages/auth/src/index.tsindex 8c419919..fd95ab9c 100644--- a/packages/auth/src/index.ts+++ b/packages/auth/src/index.ts@@ -743,7 +743,10 @@ function createAuth() {? eq(schema.user.email, (body?.email ?? '').trim().toLowerCase()): eq(schema.user.username, (body?.username ?? '').trim().toLowerCase());if (await isUnverified(identifier)) {+ // The code is better-auth's own for this refusal; the sign-in form tells it+ // apart from the other 403s, such as a deactivated account, by it.throw new APIError('FORBIDDEN', {+ code: 'EMAIL_NOT_VERIFIED',message: 'Confirm your email address before signing in',});}