Skip to content

Commit 406eba0

Browse files
committed
Improve GitHub OAuth configuration and environment variable handling
- Add null checks for GitHub OAuth strategy configuration - Make GitHub-related environment variables optional - Update auth strategy initialization to handle missing credentials gracefully
1 parent 5946e50 commit 406eba0

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

app/utils/auth.server.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export const sessionKey = 'sessionId'
1919
export const authenticator = new Authenticator<ProviderUser>()
2020

2121
for (const [providerName, provider] of Object.entries(providers)) {
22-
authenticator.use(provider.getAuthStrategy(), providerName)
22+
const strategy = provider.getAuthStrategy()
23+
if (strategy) {
24+
authenticator.use(strategy, providerName)
25+
}
2326
}
2427

2528
export async function getUserId(request: Request) {

app/utils/env.server.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ const schema = z.object({
88
INTERNAL_COMMAND_TOKEN: z.string(),
99
HONEYPOT_SECRET: z.string(),
1010
CACHE_DATABASE_PATH: z.string(),
11-
// If you plan on using Sentry, uncomment this line
12-
// SENTRY_DSN: z.string(),
13-
// If you plan to use Resend, uncomment this line
14-
// RESEND_API_KEY: z.string(),
15-
// If you plan to use GitHub auth, remove the default:
16-
GITHUB_CLIENT_ID: z.string().default('MOCK_GITHUB_CLIENT_ID'),
17-
GITHUB_CLIENT_SECRET: z.string().default('MOCK_GITHUB_CLIENT_SECRET'),
18-
GITHUB_REDIRECT_URI: z.string().default('MOCK_GITHUB_REDIRECT_URI'),
19-
GITHUB_TOKEN: z.string().default('MOCK_GITHUB_TOKEN'),
11+
// If you plan on using Sentry, remove the .optional()
12+
SENTRY_DSN: z.string().optional(),
13+
// If you plan to use Resend, remove the .optional()
14+
RESEND_API_KEY: z.string().optional(),
15+
// If you plan to use GitHub auth, remove the .optional()
16+
GITHUB_CLIENT_ID: z.string().optional(),
17+
GITHUB_CLIENT_SECRET: z.string().optional(),
18+
GITHUB_REDIRECT_URI: z.string().optional(),
19+
GITHUB_TOKEN: z.string().optional(),
20+
2021
ALLOW_INDEXING: z.enum(['true', 'false']).optional(),
2122

2223
// Tigris Object Storage Configuration

app/utils/providers/github.server.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ const GitHubUserResponseSchema = z.object({
4242

4343
export class GitHubProvider implements AuthProvider {
4444
getAuthStrategy() {
45+
if (
46+
!process.env.GITHUB_CLIENT_ID ||
47+
!process.env.GITHUB_CLIENT_SECRET ||
48+
!process.env.GITHUB_REDIRECT_URI
49+
) {
50+
console.log(
51+
'GitHub OAuth strategy not available because environment variables are not set',
52+
)
53+
return null
54+
}
4555
return new GitHubStrategy(
4656
{
4757
clientId: process.env.GITHUB_CLIENT_ID,

app/utils/providers/provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type ProviderUser = {
1111
}
1212

1313
export interface AuthProvider {
14-
getAuthStrategy(): Strategy<ProviderUser, any>
14+
getAuthStrategy(): Strategy<ProviderUser, any> | null
1515
handleMockAction(request: Request): Promise<void>
1616
resolveConnectionData(
1717
providerId: string,

0 commit comments

Comments
 (0)