overlayed
overlayed copied to clipboard
Implement `refresh_token` logic for authentication
The code here has access to the refresh_token
so we should implement refresh logic so you don't have to login again if the token expires.
Looks like the tokens are valid for 7 week (604800
seconds).
https://github.com/overlayeddev/overlayed/blob/4080a45044490ae1f9cfd8aa5886e157d4b51d20/apps/desktop/src/rpc/manager.ts#L278-L281
High level impl would be something like this:
- [ ] add new versioned API route
/v2/token/refresh
to hit discord API to refresh - (api handler) - [ ] if the token age is older than expiry then refresh it via new endpoint
- [ ] store the tokens in local storage, probably a good idea to separate them by uid (switching users causes issues)
{
"1203894712038974": {
authdata: {
refreshToken: "...", accessToken: "...", expiresAt: "..." }
},
userdata: {
id: "98723897"
}
}