| 74 | }; |
| 75 | |
| 76 | export const sendRefreshTokenReq = async (refreshToken: string) => { |
| 77 | const appKey = PRO_CLIENT_ID ?? "cli-"; // hard-code |
| 78 | try { |
| 79 | console.info("start auto getting refreshed Remotely Save access token."); |
| 80 | const resp1 = await fetch(`${site}/api/v1/oauth2/token`, { |
| 81 | method: "POST", |
| 82 | body: new URLSearchParams({ |
| 83 | grant_type: "refresh_token", |
| 84 | refresh_token: refreshToken, |
| 85 | client_id: appKey, |
| 86 | scope: "pro.list.read", |
| 87 | }), |
| 88 | }); |
| 89 | const resp2: AuthResError | AuthResSucc = await resp1.json(); |
| 90 | console.info("finish auto getting refreshed Remotely Save access token."); |
| 91 | return resp2; |
| 92 | } catch (e) { |
| 93 | console.error(e); |
| 94 | throw e; |
| 95 | } |
| 96 | }; |
| 97 | |
| 98 | interface AuthResError { |
| 99 | error: "invalid_request"; |