-
Notifications
You must be signed in to change notification settings - Fork 290
/
Copy pathconfigTypes.ts
133 lines (127 loc) · 3.92 KB
/
configTypes.ts
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import Cookies from 'cookies'
import { PageURL } from './redirectTypes'
import { User } from './createUser'
import { Spread } from './Spread'
type OnErrorHandler = (error: Error) => void
// https://github.com/gladly-team/next-firebase-auth#config
export interface ConfigInput {
/**
* The redirect destination URL when redirecting to the login page.
*/
authPageURL?: PageURL
/**
* The redirect destination URL when redirecting to the app.
*/
appPageURL?: PageURL
/**
* The API endpoint to call on auth state change for an authenticated user.
*/
loginAPIEndpoint?: string
/**
* The API endpoint to call on auth state change for a signed-out user.
*/
logoutAPIEndpoint?: string
/**
* Handler called if there are unexpected errors while verifying the user's
* ID token server-side.
*/
onVerifyTokenError?: OnErrorHandler
/**
* Handler called if there are unexpected errors while refreshing the
* user's ID token server-side.
*/
onTokenRefreshError?: OnErrorHandler
/**
* A handler to call on auth state changes. More info:
* https://github.com/gladly-team/next-firebase-auth#tokenchangedhandler
*/
tokenChangedHandler?: (user: User) => void
/**
* Handler called if the login API endpoint returns a non-200 response.
* Not used if a custom "tokenChangedHandler" is defined. If a handler is
* not defined, this library will throw on any non-200 responses.
*/
onLoginRequestError?: OnErrorHandler
/**
* Handler called if the logout API endpoint returns a non-200 response. Not
* used if a custom "tokenChangedHandler" is defined. If a handler is not
* defined, this library will throw on any non-200 responses.
*/
onLogoutRequestError?: OnErrorHandler
/**
* Whether to use application default credentials with firebase-admin.
*/
useFirebaseAdminDefaultCredential?: boolean
/**
* The config passed to the Firebase admin SDK's `initializeApp`. Not
* required if your app manually is initializing the admin SDK elsewhere.
*/
firebaseAdminInitConfig?: {
credential: {
projectId: string
clientEmail: string
privateKey: string
}
databaseURL?: string
}
/**
* The Firebase auth emulator host address on the user's machine. Must match
* the value of the `FIREBASE_AUTH_EMULATOR_HOST` environment variable.
* https://firebase.google.com/docs/emulator-suite/connect_auth
*/
firebaseAuthEmulatorHost?: string
/**
* The config passed to the Firebase client JS SDK's `initializeApp`.
*/
firebaseClientInitConfig: {
apiKey: string
projectId?: string
appId?: string
// "PROJECT_ID.firebaseapp.com"
authDomain?: string
// "https://PROJECT_ID.firebaseio.com"
databaseURL?: string
// "PROJECT_ID.appspot.com"
storageBucket?: string
// "SENDER_ID"
messagingSenderId?: string
// "G-MEASUREMENT_ID"
measurementId?: string
}
tenantId?: string
cookies: Omit<Cookies.Option & Cookies.SetOption, 'sameSite'> & {
// The base name for the auth cookies.
name: string
sameSite: string
}
/**
* When true, will log events.
*/
debug?: boolean
}
const ONE_WEEK_IN_MS = 7 * 60 * 60 * 24 * 1000
export const defaultConfig = {
debug: false,
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
onVerifyTokenError: (_err: Error) => {},
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
onTokenRefreshError: (_err: Error) => {},
cookies: {
// Required to be provided by the user.
// name: undefined,
httpOnly: true,
maxAge: ONE_WEEK_IN_MS,
overwrite: true,
path: '/',
sameSite: 'strict',
secure: true,
signed: true,
},
}
export type ConfigDefault = typeof defaultConfig
export type ConfigMerged = Omit<
Spread<[ConfigInput, ConfigDefault]>,
'cookies'
> & {
cookies: Spread<[ConfigInput['cookies'], ConfigDefault['cookies']]>
}