@@ -18,22 +18,44 @@ import { isStripeEnabled, stripe } from "@/utils/stripe.ts";
18
18
19
19
const oauth2Client = createGitHubOAuth2Client ( ) ;
20
20
21
- // deno-lint-ignore no-explicit-any
22
- async function getGitHubUser ( accessToken : string ) : Promise < any > {
21
+ interface GitHubUser {
22
+ login : string ;
23
+ email : string ;
24
+ }
25
+
26
+ /**
27
+ * Returns the GitHub profile information of the user with the given access
28
+ * token.
29
+ *
30
+ * @see {@link https://docs.github.com/en/rest/users/users?apiVersion=2022-11-28#get-the-authenticated-user }
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import { getGitHubUser } from "@/plugins/kv_oauth.ts";
35
+ *
36
+ * const user = await getGitHubUser("<access token>");
37
+ * user.login; // Returns "octocat"
38
+ * user.email; // Returns "[email protected] "
39
+ * ```
40
+ */
41
+ export async function getGitHubUser ( accessToken : string ) {
23
42
const response = await fetch ( "https://api.github.com/user" , {
24
43
headers : { authorization : `Bearer ${ accessToken } ` } ,
25
44
} ) ;
26
45
if ( ! response . ok ) {
27
46
const { message } = await response . json ( ) ;
28
47
throw new Error ( message ) ;
29
48
}
30
- return await response . json ( ) ;
49
+ return await response . json ( ) as Promise < GitHubUser > ;
31
50
}
32
51
33
52
/**
34
- * This custom plugin centralizes all authentication logic using the {@link https://deno.land/x/deno_kv_oauth|Deno KV OAuth} module.
53
+ * This custom plugin centralizes all authentication logic using the
54
+ * {@link https://deno.land/x/deno_kv_oauth|Deno KV OAuth} module.
35
55
*
36
- * The implementation is based off Deno KV OAuth's own {@link https://deno.land/x/deno_kv_oauth/src/fresh_plugin.ts?source|Fresh plugin implementation}.
56
+ * The implementation is based off Deno KV OAuth's own
57
+ * {@link https://deno.land/x/deno_kv_oauth/src/fresh_plugin.ts?source|Fresh plugin}
58
+ * implementation.
37
59
*/
38
60
export default {
39
61
name : "kv-oauth" ,
0 commit comments