Skip to content

Commit 8a2b309

Browse files
jakub.vilhanjakub.vilhan
jakub.vilhan
authored and
jakub.vilhan
committed
Change return type to string for getToken fn
1 parent d6cd86e commit 8a2b309

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/callback-endpoint.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,13 @@ export const createCallbackEndpoint = (
4242
// obtain access token
4343
// /////////////////////////////////////
4444

45-
let tokenData;
45+
let access_token: string;
4646

4747
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}`);
4952
} else {
5053
const tokenResponse = await fetch(pluginOptions.tokenEndpoint, {
5154
method: "POST",
@@ -61,12 +64,13 @@ export const createCallbackEndpoint = (
6164
grant_type: "authorization_code",
6265
}).toString(),
6366
});
64-
tokenData = await tokenResponse.json();
65-
}
67+
const tokenData = await tokenResponse.json();
6668

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+
}
7074

7175
// /////////////////////////////////////
7276
// get user info

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export interface PluginTypes {
115115
* Function to get token from the OAuth providers.
116116
* If its not provided default will be used.
117117
*/
118-
getToken?: (code: string) => Promise<any> | any;
118+
getToken?: (code: string) => string;
119119

120120
/**
121121
* Redirect users after successful login.

0 commit comments

Comments
 (0)