Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix: move verification service to it's own export
Brad Barbinb6d36b02ce37
diff --git a/apps/erp/app/routes/_public+/login.tsx b/apps/erp/app/routes/_public+/login.tsxindex 0d9e45a931..e7f36d6b97 100644--- a/apps/erp/app/routes/_public+/login.tsx+++ b/apps/erp/app/routes/_public+/login.tsx@@ -4,13 +4,10 @@ import {error,magicLinkValidator,} from "@carbon/auth";-import {- sendMagicLink,- sendVerificationCode,- verifyAuthSession,-} from "@carbon/auth/auth.server";+import { sendMagicLink, verifyAuthSession } from "@carbon/auth/auth.server";import { flash, getAuthSession } from "@carbon/auth/session.server";import { getUserByEmail } from "@carbon/auth/users.server";+import { sendVerificationCode } from "@carbon/auth/verification.server";import { Hidden, Input, Submit, ValidatedForm, validator } from "@carbon/form";import { redis } from "@carbon/kv";import {diff --git a/apps/erp/app/routes/_public+/verify.tsx b/apps/erp/app/routes/_public+/verify.tsxindex a2f1322ced..acc392715e 100644--- a/apps/erp/app/routes/_public+/verify.tsx+++ b/apps/erp/app/routes/_public+/verify.tsx@@ -2,13 +2,13 @@ import { assertIsPost, error } from "@carbon/auth";import {createEmailAuthAccount,signInWithEmail,- verifyEmailCode,} from "@carbon/auth/auth.server";import {flash,getAuthSession,setAuthSession,} from "@carbon/auth/session.server";+import { verifyEmailCode } from "@carbon/auth/verification.server";import { Hidden, InputOTP, ValidatedForm, validator } from "@carbon/form";import { redis } from "@carbon/kv";import {diff --git a/packages/auth/package.json b/packages/auth/package.jsonindex 6a09782c50..9f4788034a 100644--- a/packages/auth/package.json+++ b/packages/auth/package.json@@ -17,7 +17,8 @@"./autodesk.server": "./src/services/autodesk.server.ts","./company.server": "./src/services/company.server.ts","./session.server": "./src/services/session.server.ts",- "./users.server": "./src/services/users.server.ts"+ "./users.server": "./src/services/users.server.ts",+ "./verification.server": "./src/services/verification.server.ts"},"main": "./src/index.ts","types": "./src/index.ts",diff --git a/packages/auth/src/services/auth.server.ts b/packages/auth/src/services/auth.server.tsindex 6d6b137f0f..2d5095b2f2 100644--- a/packages/auth/src/services/auth.server.ts+++ b/packages/auth/src/services/auth.server.ts@@ -15,10 +15,6 @@ import {import { getCompaniesForUser } from "./users";import { getUserClaims } from "./users.server";-import { VerificationEmail } from "@carbon/documents/email";-import { redis } from "@carbon/kv";-import { resend } from "@carbon/lib/resend.server";-import { render } from "@react-email/components";import { getCarbonAPIKeyClient } from "../lib/supabase/client";import type { AuthSession } from "../types";import { error } from "../utils/result";@@ -271,55 +267,3 @@ export async function verifyAuthSession(authSession: AuthSession) {return Boolean(authAccount);}--export async function sendVerificationCode(email: string) {- try {- // Generate 6-digit verification code- const verificationCode = Math.floor(- 100000 + Math.random() * 900000- ).toString();-- // Store in Redis with 10-minute expiration- await redis.set(`verification:${email.toLowerCase()}`, verificationCode, {- ex: 600,- });-- // Send email with verification code using React template- const html = await render(- VerificationEmail({- email,- verificationCode,- })- );-- const result = await resend.emails.send({- from: "Carbon <[email protected]>",- to: email,- subject: "Verify your email address",- html,- });-- return !result.error;- } catch (error) {- console.error("Failed to send verification code:", error);- return false;- }-}--export async function verifyEmailCode(email: string, code: string) {- try {- const storedCode = await redis.get(`verification:${email.toLowerCase()}`);-- if (!storedCode || String(storedCode).trim() !== String(code).trim()) {- return false;- }-- // Delete the code after successful verification- await redis.del(`verification:${email.toLowerCase()}`);-- return true;- } catch (error) {- console.error("Failed to verify email code:", error);- return false;- }-}diff --git a/packages/auth/src/services/verification.server.ts b/packages/auth/src/services/verification.server.tsnew file mode 100644index 0000000000..ffddf7c4d5--- /dev/null+++ b/packages/auth/src/services/verification.server.ts@@ -0,0 +1,56 @@+import { VerificationEmail } from "@carbon/documents/email";+import { redis } from "@carbon/kv";+import { resend } from "@carbon/lib/resend.server";+import { render } from "@react-email/components";++export async function sendVerificationCode(email: string) {+ try {+ // Generate 6-digit verification code+ const verificationCode = Math.floor(+ 100000 + Math.random() * 900000+ ).toString();++ // Store in Redis with 10-minute expiration+ await redis.set(`verification:${email.toLowerCase()}`, verificationCode, {+ ex: 600,+ });++ // Send email with verification code using React template+ const html = await render(+ VerificationEmail({+ email,+ verificationCode,+ })+ );++ const result = await resend.emails.send({+ from: "Carbon <[email protected]>",+ to: email,+ subject: "Verify your email address",+ html,+ });++ return !result.error;+ } catch (error) {+ console.error("Failed to send verification code:", error);+ return false;+ }+}++export async function verifyEmailCode(email: string, code: string) {+ try {+ const storedCode = await redis.get(`verification:${email.toLowerCase()}`);++ if (!storedCode || String(storedCode).trim() !== String(code).trim()) {+ return false;+ }++ // Delete the code after successful verification+ await redis.del(`verification:${email.toLowerCase()}`);++ return true;+ } catch (error) {+ console.error("Failed to verify email code:", error);+ return false;+ }+}