Skip to content

Commit 466079c

Browse files
committed
pkg:auth:ref: enahnce and update configuration
1 parent e47baaa commit 466079c

1 file changed

Lines changed: 29 additions & 38 deletions

File tree

packages/auth/src/configs/auth.config.ts

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ interface Env {
5151
// delete: (key: string) => Promise<void>;
5252
// }
5353

54+
const PROD_APP_URL = 'https://app.deepcrawl.dev';
55+
const PROD_AUTH_WORKER_URL = 'https://auth.deepcrawl.dev';
56+
5457
export const ALLOWED_ORIGINS = [
5558
// Production origins
59+
PROD_APP_URL,
60+
PROD_AUTH_WORKER_URL,
5661
'https://deepcrawl.dev',
5762
'https://api.deepcrawl.dev',
58-
'https://auth.deepcrawl.dev', // Auth worker (legacy)
59-
'https://app.deepcrawl.dev',
6063
'https://*.deepcrawl.dev',
6164
// Add explicit wildcard support for all deepcrawl.dev subdomains
6265
'*.deepcrawl.dev',
@@ -112,34 +115,20 @@ export const DEVELOPMENT_ORIGINS = [
112115

113116
export const MAX_SESSIONS = 2;
114117

115-
const USE_OAUTH_PROXY = false;
118+
const USE_OAUTH_PROXY = true;
116119

117120
const getBaseURL = (envUrl: string | undefined): string => {
118-
try {
119-
if (!envUrl) {
120-
throw new Error('URL is not defined');
121-
}
122-
123-
// If URL doesn't start with protocol, assume https
124-
const urlWithProtocol = envUrl.startsWith('http')
125-
? envUrl
126-
: `https://${envUrl}`;
127-
128-
// Create URL object and ensure no trailing slash
129-
const url = new URL(urlWithProtocol);
130-
131-
// Remove trailing slash from pathname to prevent double slashes
132-
if (url.pathname.endsWith('/') && url.pathname.length > 1) {
133-
url.pathname = url.pathname.slice(0, -1);
134-
}
135-
136-
// Return the URL without trailing slash
137-
return url.toString();
138-
} catch (error) {
139-
console.error('Invalid URL:', envUrl, error);
140-
// Provide fallback or throw meaningful error
141-
throw new Error(`Invalid URL: ${envUrl}`);
121+
if (!envUrl) {
122+
throw new Error('❌ [getBaseURL] URL is not defined');
142123
}
124+
125+
// Add protocol if missing
126+
const urlWithProtocol = envUrl.startsWith('http')
127+
? envUrl
128+
: `https://${envUrl}`;
129+
130+
// Remove trailing slash
131+
return urlWithProtocol.replace(/\/+$/, '');
143132
};
144133

145134
export const PLAYGROUND_API_KEY_CONFIG = {
@@ -212,7 +201,9 @@ export function createAuthConfig(env: Env) {
212201
? [
213202
oAuthProxy({
214203
currentURL: baseAuthURL,
215-
productionURL: appURL,
204+
productionURL: useAuthWorker
205+
? PROD_AUTH_WORKER_URL
206+
: PROD_APP_URL,
216207
}),
217208
]
218209
: []),
@@ -256,9 +247,7 @@ export function createAuthConfig(env: Env) {
256247

257248
// TODO: CHECK THE USER REDIRECTING FUNCTIONALITIES
258249
// Use custom callback URL instead of built-in URL
259-
const customUrl = isDevelopment
260-
? `http://localhost:3000/magic-link?token=${token}`
261-
: `${appURL}/magic-link?token=${token}`;
250+
const customUrl = `${appURL}/magic-link?token=${token}`;
262251

263252
try {
264253
await sendEmail(resend, {
@@ -279,18 +268,16 @@ export function createAuthConfig(env: Env) {
279268
}),
280269
passkey({
281270
rpName: 'DeepCrawl Auth',
282-
rpID: isDevelopment ? 'localhost' : 'auth.deepcrawl.dev',
283-
origin: isDevelopment ? 'http://localhost:3000' : appURL,
271+
origin: appURL,
272+
rpID: isDevelopment ? 'localhost' : 'deepcrawl.dev',
284273
}),
285274
organization({
286275
async sendInvitationEmail(data) {
287276
if (!emailEnabled || !resend) {
288277
return;
289278
}
290279

291-
const inviteLink = isDevelopment
292-
? `http://localhost:3000/accept-invitation?invitationId=${data.id}`
293-
: `${appURL}/accept-invitation?invitationId=${data.id}`;
280+
const inviteLink = `${appURL}/accept-invitation?invitationId=${data.id}`;
294281

295282
try {
296283
await sendEmail(resend, {
@@ -370,14 +357,18 @@ export function createAuthConfig(env: Env) {
370357
clientId: env.GITHUB_CLIENT_ID,
371358
clientSecret: env.GITHUB_CLIENT_SECRET,
372359
redirectURI: USE_OAUTH_PROXY
373-
? `${baseAuthURL}/api/auth/callback/github`
360+
? useAuthWorker
361+
? `${PROD_AUTH_WORKER_URL}/api/auth/callback/github`
362+
: `${PROD_APP_URL}/api/auth/callback/github`
374363
: undefined,
375364
},
376365
google: {
377366
clientId: env.NEXT_PUBLIC_GOOGLE_CLIENT_ID,
378367
clientSecret: env.GOOGLE_CLIENT_SECRET,
379368
redirectURI: USE_OAUTH_PROXY
380-
? `${baseAuthURL}/api/auth/callback/google`
369+
? useAuthWorker
370+
? `${PROD_AUTH_WORKER_URL}/api/auth/callback/google`
371+
: `${PROD_APP_URL}/api/auth/callback/google`
381372
: undefined,
382373
},
383374
},

0 commit comments

Comments
 (0)