-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.config.ts
More file actions
71 lines (68 loc) · 2.13 KB
/
Copy pathauth.config.ts
File metadata and controls
71 lines (68 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { NextAuthConfig } from 'next-auth';
import { createNextAuthProviders } from './lib/auth/providers';
import { configureOAuthProviders, logError } from './lib/auth/error-handler';
import { ErrorType, createAppError } from './lib/utils/error-handler';
import { authConfig } from '@/lib/config/config-service';
const configureProviders = () => {
try {
const oauthProviders = configureOAuthProviders();
return createNextAuthProviders({
google: oauthProviders.find((p) => p.id === 'google')
? {
enabled: true,
clientId: authConfig.google.clientId || '',
clientSecret: authConfig.google.clientSecret || '',
options: {
allowDangerousEmailAccountLinking: false,
},
}
: { enabled: false },
github: oauthProviders.find((p) => p.id === 'github')
? {
enabled: true,
clientId: authConfig.github.clientId || '',
clientSecret: authConfig.github.clientSecret || '',
}
: { enabled: false },
facebook: oauthProviders.find((p) => p.id === 'facebook')
? {
enabled: true,
clientId: authConfig.facebook.clientId || '',
clientSecret: authConfig.facebook.clientSecret || '',
}
: { enabled: false },
twitter: oauthProviders.find((p) => p.id === 'twitter')
? {
enabled: true,
clientId: authConfig.twitter.clientId || '',
clientSecret: authConfig.twitter.clientSecret || '',
}
: { enabled: false },
credentials: {
enabled: true,
},
});
} catch (error) {
// Log the error but continue with only credentials provider
const appError = createAppError(
'Failed to configure OAuth providers. Falling back to credentials only.',
ErrorType.CONFIG,
'OAUTH_CONFIG_FAILED',
error
);
logError(appError, 'Auth Config');
// Fallback to credentials only
return createNextAuthProviders({
credentials: { enabled: true },
google: { enabled: false },
github: { enabled: false },
facebook: { enabled: false },
twitter: { enabled: false },
});
}
};
// Notice this is only an object, not a full Auth.js instance
export default {
trustHost: true,
providers: configureProviders(),
} satisfies NextAuthConfig;