Skip to content

Commit 27e7143

Browse files
authored
Merge pull request #7 from hasnaintypes/feat/subhan-fixes-issue1
Feat/subhan fixes issue1
2 parents e347663 + a5cb568 commit 27e7143

34 files changed

+11270
-13161
lines changed

.github/workflows/ci.yml

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,78 +10,91 @@ jobs:
1010
lint-and-typecheck:
1111
name: Lint & Type Check
1212
runs-on: ubuntu-latest
13-
13+
1414
steps:
1515
- name: Checkout code
1616
uses: actions/checkout@v4
1717

18-
- name: Setup Node.js
18+
# Setup pnpm (uses version from package.json automatically)
19+
- name: Setup pnpm
20+
uses: pnpm/action-setup@v4
21+
22+
# Setup Node.js
23+
- name: Setup Node
1924
uses: actions/setup-node@v4
2025
with:
21-
node-version: '20'
22-
cache: 'npm'
26+
node-version: 20
27+
cache: pnpm
2328

29+
# Install dependencies
2430
- name: Install dependencies
25-
run: npm ci
31+
run: pnpm install --frozen-lockfile
2632

2733
- name: Run ESLint
28-
run: npm run lint
34+
run: pnpm lint
2935
continue-on-error: true
3036

3137
- name: Type check frontend
32-
run: npx tsc --noEmit
38+
run: pnpm exec tsc --noEmit
3339

3440
- name: Type check Convex backend
35-
run: npx tsc -p convex --noEmit
41+
run: pnpm exec tsc -p convex --noEmit
42+
3643

3744
build:
3845
name: Build Application
3946
runs-on: ubuntu-latest
4047
needs: lint-and-typecheck
41-
48+
4249
steps:
4350
- name: Checkout code
4451
uses: actions/checkout@v4
4552

46-
- name: Setup Node.js
53+
- name: Setup pnpm
54+
uses: pnpm/action-setup@v4
55+
56+
- name: Setup Node
4757
uses: actions/setup-node@v4
4858
with:
49-
node-version: '20'
50-
cache: 'npm'
59+
node-version: 20
60+
cache: pnpm
5161

5262
- name: Install dependencies
53-
run: npm ci
63+
run: pnpm install --frozen-lockfile
5464

5565
- name: Set up Convex
5666
env:
5767
CONVEX_DEPLOY_KEY: ${{ secrets.CONVEX_DEPLOY_KEY }}
5868
CONVEX_DEPLOYMENT: ${{ secrets.CONVEX_DEPLOYMENT }}
59-
run: |
60-
npx convex dev --once --configure=new
69+
run: pnpm exec convex dev --once --configure=new
6170

6271
- name: Build Next.js
6372
env:
6473
CONVEX_DEPLOY_KEY: ${{ secrets.CONVEX_DEPLOY_KEY }}
6574
CONVEX_DEPLOYMENT: ${{ secrets.CONVEX_DEPLOYMENT }}
66-
run: npm run build
75+
run: pnpm build
76+
6777

6878
check-formatting:
6979
name: Check Formatting
7080
runs-on: ubuntu-latest
71-
81+
7282
steps:
7383
- name: Checkout code
7484
uses: actions/checkout@v4
7585

76-
- name: Setup Node.js
86+
- name: Setup pnpm
87+
uses: pnpm/action-setup@v4
88+
89+
- name: Setup Node
7790
uses: actions/setup-node@v4
7891
with:
79-
node-version: '20'
80-
cache: 'npm'
92+
node-version: 20
93+
cache: pnpm
8194

8295
- name: Install dependencies
83-
run: npm ci
96+
run: pnpm install --frozen-lockfile
8497

8598
- name: Check Prettier formatting
86-
run: npx prettier --check "src/**/*.{ts,tsx,js,jsx,json,css,md}" "convex/**/*.{ts,js}"
87-
continue-on-error: true
99+
run: pnpm exec prettier --check "src/**/*.{ts,tsx,js,jsx,json,css,md}" "convex/**/*.{ts,js}"
100+
continue-on-error: true

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ sendable-ai/
147147
│ ├── auth/ # Authentication logic
148148
│ ├── betterAuth/ # Better Auth configuration
149149
│ ├── emails/ # Email templates
150-
│ ├── todos/ # Example CRUD operations
151150
│ ├── users/ # User management
152151
│ └── schema.ts # Database schema
153152
├── src/

convex/_generated/api.d.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import type * as auth_mutations from "../auth/mutations.js";
1313
import type * as auth_queries from "../auth/queries.js";
1414
import type * as emails_components_BaseEmail from "../emails/components/BaseEmail.js";
1515
import type * as emails_email from "../emails/email.js";
16-
import type * as emails_magicLink from "../emails/magicLink.js";
17-
import type * as emails_resetPassword from "../emails/resetPassword.js";
18-
import type * as emails_verifyEmail from "../emails/verifyEmail.js";
19-
import type * as emails_verifyOTP from "../emails/verifyOTP.js";
16+
import type * as emails_templates_AlertEmail from "../emails/templates/AlertEmail.js";
17+
import type * as emails_templates_BaseLayout from "../emails/templates/BaseLayout.js";
18+
import type * as emails_templates_MagicLink from "../emails/templates/MagicLink.js";
19+
import type * as emails_templates_ResetPassword from "../emails/templates/ResetPassword.js";
20+
import type * as emails_templates_VerifyEmail from "../emails/templates/VerifyEmail.js";
21+
import type * as emails_templates_VerifyOTP from "../emails/templates/VerifyOTP.js";
2022
import type * as http from "../http.js";
21-
import type * as todos_mutations from "../todos/mutations.js";
22-
import type * as todos_queries from "../todos/queries.js";
2323

2424
import type {
2525
ApiFromModules,
@@ -33,13 +33,13 @@ declare const fullApi: ApiFromModules<{
3333
"auth/queries": typeof auth_queries;
3434
"emails/components/BaseEmail": typeof emails_components_BaseEmail;
3535
"emails/email": typeof emails_email;
36-
"emails/magicLink": typeof emails_magicLink;
37-
"emails/resetPassword": typeof emails_resetPassword;
38-
"emails/verifyEmail": typeof emails_verifyEmail;
39-
"emails/verifyOTP": typeof emails_verifyOTP;
36+
"emails/templates/AlertEmail": typeof emails_templates_AlertEmail;
37+
"emails/templates/BaseLayout": typeof emails_templates_BaseLayout;
38+
"emails/templates/MagicLink": typeof emails_templates_MagicLink;
39+
"emails/templates/ResetPassword": typeof emails_templates_ResetPassword;
40+
"emails/templates/VerifyEmail": typeof emails_templates_VerifyEmail;
41+
"emails/templates/VerifyOTP": typeof emails_templates_VerifyOTP;
4042
http: typeof http;
41-
"todos/mutations": typeof todos_mutations;
42-
"todos/queries": typeof todos_queries;
4343
}>;
4444

4545
/**

convex/auth/helpers.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { components } from "../_generated/api";
1+
import { components, api } from "../_generated/api";
22
import authSchema from "../betterAuth/schema";
33
import { createClient, GenericCtx } from "@convex-dev/better-auth";
44
import { betterAuth, type BetterAuthOptions } from "better-auth/minimal";
@@ -11,12 +11,6 @@ import {
1111
magicLink,
1212
emailOTP,
1313
} from "better-auth/plugins";
14-
import {
15-
sendMagicLink,
16-
sendOTPVerification,
17-
sendEmailVerification,
18-
sendResetPassword,
19-
} from "../emails/email";
2014
import { requireActionCtx } from "@convex-dev/better-auth/utils";
2115
import { DataModel } from "../_generated/dataModel";
2216
import authConfig from "../auth.config";
@@ -29,13 +23,18 @@ export const authComponent = createClient<DataModel, typeof authSchema>(
2923
local: {
3024
schema: authSchema,
3125
},
32-
verbose: false,
26+
verbose: true,
3327
},
3428
);
3529

3630
export const createAuthOptions = (ctx: GenericCtx<DataModel>) => {
31+
const finalSiteUrl = (process.env.SITE_URL || process.env.BETTER_AUTH_URL || "https://localhost:3000") as string;
32+
if (!process.env.SITE_URL && !process.env.BETTER_AUTH_URL) {
33+
console.warn("WARNING: SITE_URL or BETTER_AUTH_URL is not set in Convex environment variables. This will cause INVALID_ORIGIN errors.");
34+
}
3735
return {
38-
baseURL: siteUrl,
36+
baseURL: finalSiteUrl,
37+
trustedOrigins: [finalSiteUrl],
3938
database: authComponent.adapter(ctx),
4039
account: {
4140
accountLinking: {
@@ -45,19 +44,24 @@ export const createAuthOptions = (ctx: GenericCtx<DataModel>) => {
4544
},
4645
emailVerification: {
4746
sendVerificationEmail: async ({ user, url }) => {
48-
await sendEmailVerification(requireActionCtx(ctx), {
47+
// Ensure the URL uses the correct protocol and path
48+
const verificationUrl = url.replace("http://localhost:3000", finalSiteUrl)
49+
.replace("/api/auth/verify-email", "/verify-email");
50+
51+
await requireActionCtx(ctx).runAction(api.emails.email.sendEmailVerification, {
4952
to: user.email,
50-
url,
53+
url: verificationUrl,
5154
});
5255
},
5356
},
5457
emailAndPassword: {
5558
enabled: true,
5659
requireEmailVerification: true,
5760
sendResetPassword: async ({ user, url }) => {
58-
await sendResetPassword(requireActionCtx(ctx), {
61+
const resetPasswordUrl = url.replace("http://localhost:3000", finalSiteUrl);
62+
await requireActionCtx(ctx).runAction(api.emails.email.sendResetPassword, {
5963
to: user.email,
60-
url,
64+
url: resetPasswordUrl,
6165
});
6266
},
6367
},
@@ -89,15 +93,15 @@ export const createAuthOptions = (ctx: GenericCtx<DataModel>) => {
8993
username(),
9094
magicLink({
9195
sendMagicLink: async ({ email, url }) => {
92-
await sendMagicLink(requireActionCtx(ctx), {
96+
await requireActionCtx(ctx).runAction(api.emails.email.sendMagicLink, {
9397
to: email,
9498
url,
9599
});
96100
},
97101
}),
98102
emailOTP({
99103
async sendVerificationOTP({ email, otp }) {
100-
await sendOTPVerification(requireActionCtx(ctx), {
104+
await requireActionCtx(ctx).runAction(api.emails.email.sendOTPVerification, {
101105
to: email,
102106
code: otp,
103107
});

0 commit comments

Comments
 (0)