@@ -98,40 +98,45 @@ export class DiscordMetadata extends Service {
98
98
. catch ( async ( err : AxiosError < OAuthErrorData > ) => {
99
99
const discordResponse = err . response ?. data ;
100
100
if ( discordResponse ?. error === "invalid_grant" ) {
101
- // The provided authorization grant (e.g., authorization
102
- // code, resource owner credentials) or refresh token is
103
- // invalid, expired, revoked, does not match the redirection
104
- // URI used in the authorization request, or was issued to
105
- // another client.
101
+ // The provided authorization grant or refresh token is
102
+ // invalid, expired, revoked, doesn't match redirection
103
+ // URI, or was issued to another client.
106
104
const res = await revokeOAuthToken ( data . access_token ) ;
107
105
console . warn (
108
106
`[Metadata] InValID_GraNT revoking token (${ res } )! ${ userId } [${
109
107
err . code
110
108
} ] ${ JSON . stringify ( discordResponse ) } `
111
109
) ;
112
- } else
110
+ } else {
113
111
console . error (
114
112
`[Metadata] failed fetching tokens: [${ err . code } ] ${ JSON . stringify (
115
113
discordResponse
116
114
) } `
117
115
) ;
116
+ }
118
117
} ) ;
119
- if ( ! res ) return ;
120
118
121
- const token = res . data ;
122
- await (
123
- await this . sql . getLocalDatabase ( )
124
- ) . run (
125
- "UPDATE discord_tokens SET access_token = $access_token, refresh_token = $refresh_token, expires_at = $expires_at WHERE user_id = $user_id" ,
126
- {
127
- $user_id : userId ,
128
- $access_token : token . access_token ,
129
- $refresh_token : token . refresh_token ,
130
- $expires_at : Date . now ( ) + token . expires_in * 1000 ,
131
- }
119
+ if ( res && "data" in res ) {
120
+ const token = res . data ;
121
+ const db = await this . sql . getLocalDatabase ( ) ;
122
+ await db . run (
123
+ "UPDATE discord_tokens SET access_token = ?, refresh_token = ?, expires_at = ? WHERE user_id = ?" ,
124
+ [
125
+ token . access_token ,
126
+ token . refresh_token ,
127
+ Date . now ( ) + token . expires_in * 1000 ,
128
+ userId ,
129
+ ]
130
+ ) ;
131
+ return token . access_token ;
132
+ }
133
+ console . error (
134
+ `[Metadata] failed to get access token for ${ userId } data: ${ JSON . stringify (
135
+ data
136
+ ) } res: ${ JSON . stringify ( res ) } `
132
137
) ;
133
- return token . access_token ;
134
138
}
139
+
135
140
return data . access_token ;
136
141
}
137
142
0 commit comments