fix type errors
This commit is contained in:
@@ -86,7 +86,7 @@ export function requestAccessToken(client_id: string, ...scopes: Array<string>)
|
||||
* @param {Array<string>|string} scopes
|
||||
* @returns {Promise<AuthCode>}
|
||||
*/
|
||||
export function requestAuthCode(client_id: string, ...scopes: Array<string>): Promise<any> {
|
||||
export function requestAuthCode(client_id: string, ...scopes: Array<string>): Promise<never> {
|
||||
console.debug('requesting authorization code')
|
||||
const url = new URL('https://id.twitch.tv/oauth2/authorize')
|
||||
url.searchParams.append('response_type', 'code')
|
||||
@@ -178,7 +178,7 @@ export function refreshToken(client_id: string, refresh_token: string): Promise<
|
||||
* @param {string} client_id
|
||||
* @returns {TwitchToken}
|
||||
*/
|
||||
export async function getUserToken(client_id: string, ...scopes): Promise<TwitchToken> {
|
||||
export async function getUserToken(client_id: string, ...scopes:string[]): Promise<TwitchToken> {
|
||||
const token=await getUserTokenPassive(client_id, ...scopes)
|
||||
if(!token){
|
||||
return requestAuthCode(client_id, ...scopes)
|
||||
@@ -193,19 +193,19 @@ export async function getUserToken(client_id: string, ...scopes): Promise<Twitch
|
||||
* @param {string} client_id
|
||||
* @returns {TwitchToken}
|
||||
*/
|
||||
export async function getUserTokenPassive(client_id: string, ...scopes): Promise<TwitchToken>{
|
||||
export async function getUserTokenPassive(client_id: string, ...scopes:string[]): Promise<TwitchToken|null>{
|
||||
console.debug('scopes requested:',...scopes)
|
||||
const params = new URLSearchParams(location.search + '&' + location.hash.substring(1))
|
||||
if (params.has('code')) {
|
||||
const code = params.get('code')
|
||||
const code = params.get('code')!
|
||||
history.replaceState(null, '', redirect_uri)
|
||||
return exchangeCode(client_id, code)
|
||||
}
|
||||
if (params.has('refresh_token')) {
|
||||
return refreshToken(client_id, params.get('refresh_token'))
|
||||
return refreshToken(client_id, params.get('refresh_token')!)
|
||||
}
|
||||
if (params.has('access_token')) {
|
||||
return validateToken(params.get('access_token'))
|
||||
return validateToken(params.get('access_token')!)
|
||||
}
|
||||
if (params.has('error')) {
|
||||
const error_message = params.get('error') + ': ' + params.get('error_description')
|
||||
|
||||
Reference in New Issue
Block a user