File tree Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Expand file tree Collapse file tree 2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -42,10 +42,13 @@ export const createCallbackEndpoint = (
42
42
// obtain access token
43
43
// /////////////////////////////////////
44
44
45
- let tokenData ;
45
+ let access_token : string ;
46
46
47
47
if ( pluginOptions . getToken ) {
48
- tokenData = await pluginOptions . getToken ( code ) ;
48
+ access_token = pluginOptions . getToken ( code ) ;
49
+
50
+ if ( typeof access_token !== "string" )
51
+ throw new Error ( `No access token: ${ access_token } ` ) ;
49
52
} else {
50
53
const tokenResponse = await fetch ( pluginOptions . tokenEndpoint , {
51
54
method : "POST" ,
@@ -61,12 +64,13 @@ export const createCallbackEndpoint = (
61
64
grant_type : "authorization_code" ,
62
65
} ) . toString ( ) ,
63
66
} ) ;
64
- tokenData = await tokenResponse . json ( ) ;
65
- }
67
+ const tokenData = await tokenResponse . json ( ) ;
66
68
67
- const access_token = tokenData ?. access_token ;
68
- if ( typeof access_token !== "string" )
69
- throw new Error ( `No access token: ${ JSON . stringify ( tokenData ) } ` ) ;
69
+ access_token = tokenData ?. access_token ;
70
+
71
+ if ( typeof access_token !== "string" )
72
+ throw new Error ( `No access token: ${ JSON . stringify ( tokenData ) } ` ) ;
73
+ }
70
74
71
75
// /////////////////////////////////////
72
76
// get user info
Original file line number Diff line number Diff line change @@ -115,7 +115,7 @@ export interface PluginTypes {
115
115
* Function to get token from the OAuth providers.
116
116
* If its not provided default will be used.
117
117
*/
118
- getToken ?: ( code : string ) => Promise < any > | any ;
118
+ getToken ?: ( code : string ) => string ;
119
119
120
120
/**
121
121
* Redirect users after successful login.
You can’t perform that action at this time.
0 commit comments