Skip to content

Commit 9c5d834

Browse files
committed
Fix
1 parent 9137525 commit 9c5d834

File tree

4 files changed

+33
-15
lines changed

4 files changed

+33
-15
lines changed

bin/dev

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22

33
set -e
44

5-
if [ -f ".vercel/project.json" ]; then
6-
pnpx vercel env pull .env
7-
elif [ ! -f ".env" ]; then
8-
echo ".env file not found. Please run bin/setup first."
9-
fi
10-
115
pnpm install
126
cd backend
137
bundle install

frontend/AUTH_SETUP.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ This project now includes a parallel authentication flow using Auth.js with OTP
77
Add these environment variables to your `.env` file:
88

99
```bash
10+
# Auth.js secret (server-side only)
1011
AUTH_SECRET=your-auth-secret-here
11-
API_SECRET_TOKEN=your-api-secret-token-here
12+
13+
# API configuration (client-side accessible)
14+
NEXT_PUBLIC_API_SECRET_TOKEN=your-api-secret-token-here
15+
NEXT_PUBLIC_API_URL=http://localhost:3000 # Optional - defaults to localhost:3000 in dev
1216
```
1317

1418
### AUTH_SECRET
@@ -17,8 +21,14 @@ Generate a random secret for Auth.js:
1721
npx auth secret
1822
```
1923

20-
### API_SECRET_TOKEN
21-
This should match the API token configured in your backend for accessing the OTP endpoints.
24+
### NEXT_PUBLIC_API_SECRET_TOKEN
25+
This should match the API token configured in your backend for accessing the OTP endpoints. Uses `NEXT_PUBLIC_` prefix to make it available in client-side code.
26+
27+
### NEXT_PUBLIC_API_URL (Optional)
28+
Override the default API URL. If not set, it will auto-detect based on environment:
29+
- Development: `http://localhost:3000`
30+
- Production: `https://api.flexile.com`
31+
- Preview: Auto-generated Heroku URL
2232

2333
## How it Works
2434

frontend/env/client.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ const env = {
55
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY,
66
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
77
NEXT_PUBLIC_EQUITY_EXERCISE_DOCUSEAL_ID: process.env.NEXT_PUBLIC_EQUITY_EXERCISE_DOCUSEAL_ID,
8+
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL,
9+
NEXT_PUBLIC_API_SECRET_TOKEN: process.env.NEXT_PUBLIC_API_SECRET_TOKEN,
10+
VERCEL_ENV: process.env.VERCEL_ENV,
11+
VERCEL_GIT_PULL_REQUEST_ID: process.env.VERCEL_GIT_PULL_REQUEST_ID,
812
};
913

1014
export default z
1115
.object({
1216
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: z.string(),
1317
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string(),
1418
NEXT_PUBLIC_EQUITY_EXERCISE_DOCUSEAL_ID: z.string(),
19+
NEXT_PUBLIC_API_URL: z.string().optional(),
20+
NEXT_PUBLIC_API_SECRET_TOKEN: z.string().optional(),
21+
VERCEL_ENV: z.enum(["production", "preview", "development"]).optional(),
22+
VERCEL_GIT_PULL_REQUEST_ID: z.string().optional(),
1523
})
1624
.parse(env);

frontend/lib/auth.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
import NextAuth from "next-auth"
22
import Credentials from "next-auth/providers/credentials"
33
import { z } from "zod"
4-
import env from "@/env"
4+
import clientEnv from "@/env/client"
55

66
// Define the API base URL based on environment
77
const API_BASE_URL = (() => {
8-
switch (env.VERCEL_ENV) {
8+
// If NEXT_PUBLIC_API_URL is set, use it
9+
if (clientEnv.NEXT_PUBLIC_API_URL) {
10+
return clientEnv.NEXT_PUBLIC_API_URL
11+
}
12+
13+
// Otherwise, determine based on environment
14+
switch (clientEnv.VERCEL_ENV) {
915
case "production":
1016
return "https://api.flexile.com"
1117
case "preview":
12-
return `https://flexile-pipeline-pr-${process.env.VERCEL_GIT_PULL_REQUEST_ID}.herokuapp.com`
18+
return `https://flexile-pipeline-pr-${clientEnv.VERCEL_GIT_PULL_REQUEST_ID || 'unknown'}.herokuapp.com`
1319
default:
1420
return "http://localhost:3000"
1521
}
1622
})()
1723

18-
const API_TOKEN = env.API_SECRET_TOKEN
24+
const API_TOKEN = clientEnv.NEXT_PUBLIC_API_SECRET_TOKEN || process.env.API_SECRET_TOKEN || "your-api-token"
1925

2026
// Schema for OTP login
2127
const otpLoginSchema = z.object({
@@ -29,7 +35,7 @@ const sendOtpSchema = z.object({
2935
})
3036

3137
export const { handlers, signIn, signOut, auth } = NextAuth({
32-
secret: env.AUTH_SECRET,
38+
secret: process.env.AUTH_SECRET || "fallback-secret-for-development",
3339
providers: [
3440
Credentials({
3541
id: "otp",
@@ -86,7 +92,7 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
8692
],
8793
callbacks: {
8894
async jwt({ token, user }) {
89-
if (user) {
95+
if (user && user.jwt) {
9096
token.jwt = user.jwt
9197
}
9298
return token

0 commit comments

Comments
 (0)