Commit b6a9715 1 parent 975a0fb commit b6a9715 Copy full SHA for b6a9715
File tree 3 files changed +23
-7
lines changed
3 files changed +23
-7
lines changed Original file line number Diff line number Diff line change
1
+ type OAuthHandler = keyof typeof oauth
2
+
3
+ export default eventHandler ( async event => {
4
+ const { provider } = await getValidatedRouterParams ( event , z . object ( {
5
+ provider : z . string ( ) . min ( 1 )
6
+ } ) . parse )
7
+
8
+ const config = getConfig ( )
9
+ const oauthConfig = config . oauth ?. [ provider ]
10
+ const handlerName = `${ provider } EventHandler`
11
+ if ( ! Object . hasOwn ( oauth , handlerName ) ) {
12
+ throw createError ( { statusCode : 400 , message : 'Could not resolve this provider.' } )
13
+ }
14
+
15
+ return oauth [ handlerName as OAuthHandler ] ( {
16
+ config : oauthConfig as any ,
17
+ async onSuccess ( event , { user } ) {
18
+ await setUserSession ( event , { user } )
19
+ return sendRedirect ( event , '/todos' )
20
+ }
21
+ } ) ( event )
22
+ } )
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ export async function _fetchConfig() {
24
24
return _config
25
25
}
26
26
27
- export function useConfig ( ) {
27
+ export function getConfig ( ) {
28
28
if ( ! _config ) {
29
29
throw createError ( 'Please run _fetchConfig() in order to use useConfig()' )
30
30
}
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments