Skip to content

Commit 455df3b

Browse files
authored
chore: add types for Kick and Twitch providers (#489)
1 parent f55debb commit 455df3b

2 files changed

Lines changed: 42 additions & 8 deletions

File tree

src/runtime/server/lib/oauth/kick.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,22 @@ export interface OAuthKickConfig {
4949
redirectURL?: string
5050
}
5151

52-
export function defineOAuthKickEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthKickConfig>) {
52+
interface KickUser {
53+
email: string
54+
name: string
55+
profile_picture: string
56+
user_id: string
57+
}
58+
59+
interface KickTokens {
60+
access_token: string
61+
expires_in: number
62+
refresh_token: string
63+
scope: string
64+
token_type: string
65+
}
66+
67+
export function defineOAuthKickEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthKickConfig, { user: KickUser, tokens: KickTokens }>) {
5368
return eventHandler(async (event: H3Event) => {
5469
config = defu(config, useRuntimeConfig(event).oauth?.kick, {
5570
authorizationURL: 'https://id.kick.com/oauth/authorize',
@@ -101,9 +116,7 @@ export function defineOAuthKickEventHandler({ config, onSuccess, onError }: OAut
101116
}
102117
const accessToken = tokens.access_token
103118

104-
// TODO: improve typing
105-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
106-
const { data }: any = await $fetch('https://api.kick.com/public/v1/users', {
119+
const { data } = await $fetch<{ data: KickUser[] }>('https://api.kick.com/public/v1/users', {
107120
headers: {
108121
Authorization: `Bearer ${accessToken}`,
109122
Accept: 'application/json',

src/runtime/server/lib/oauth/twitch.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,29 @@ export interface OAuthTwitchConfig {
5858
redirectURL?: string
5959
}
6060

61-
export function defineOAuthTwitchEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthTwitchConfig>) {
61+
interface TwitchUser {
62+
id: string
63+
login: string
64+
display_name: string
65+
type: string
66+
broadcaster_type: string
67+
description: string
68+
profile_image_url: string
69+
offline_image_url: string
70+
view_count: number
71+
email?: string
72+
created_at: string
73+
}
74+
75+
interface TwitchTokens {
76+
access_token: string
77+
expires_in: number
78+
refresh_token: string
79+
scope: string[]
80+
token_type: string
81+
}
82+
83+
export function defineOAuthTwitchEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthTwitchConfig, { user: TwitchUser, tokens: TwitchTokens }>) {
6284
return eventHandler(async (event: H3Event) => {
6385
config = defu(config, useRuntimeConfig(event).oauth?.twitch, {
6486
authorizationURL: 'https://id.twitch.tv/oauth2/authorize',
@@ -107,9 +129,8 @@ export function defineOAuthTwitchEventHandler({ config, onSuccess, onError }: OA
107129
}
108130

109131
const accessToken = tokens.access_token
110-
// TODO: improve typing
111-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
112-
const users: any = await $fetch('https://api.twitch.tv/helix/users', {
132+
133+
const users = await $fetch<{ data: TwitchUser[] }>('https://api.twitch.tv/helix/users', {
113134
headers: {
114135
'Client-ID': config.clientId,
115136
'Authorization': `Bearer ${accessToken}`,

0 commit comments

Comments
 (0)