mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: manage account buttons
This commit is contained in:
parent
d4be5b8c66
commit
af4fcb8f06
12 changed files with 286 additions and 149 deletions
|
|
@ -30,6 +30,7 @@ import "./library/remove-game-from-library";
|
|||
import "./library/select-game-wine-prefix";
|
||||
import "./library/reset-game-achievements";
|
||||
import "./misc/open-checkout";
|
||||
import "./misc/open-manage-account";
|
||||
import "./misc/open-external";
|
||||
import "./misc/show-open-dialog";
|
||||
import "./misc/get-features";
|
||||
|
|
|
|||
25
src/main/events/misc/open-manage-account.ts
Normal file
25
src/main/events/misc/open-manage-account.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { shell } from "electron";
|
||||
import { registerEvent } from "../register-event";
|
||||
import { HydraApi, logger } from "@main/services";
|
||||
import { ManageAccountPage } from "@types";
|
||||
|
||||
const openManageAccount = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
page: ManageAccountPage
|
||||
) => {
|
||||
try {
|
||||
const { accessToken } = await HydraApi.refreshToken();
|
||||
|
||||
const params = new URLSearchParams({
|
||||
token: accessToken,
|
||||
});
|
||||
|
||||
shell.openExternal(
|
||||
`${import.meta.env.MAIN_VITE_AUTH_URL}/${page}?${params.toString()}`
|
||||
);
|
||||
} catch (err) {
|
||||
logger.error("Failed to open manage account", err);
|
||||
}
|
||||
};
|
||||
|
||||
registerEvent("openManageAccount", openManageAccount);
|
||||
|
|
@ -215,16 +215,20 @@ export class HydraApi {
|
|||
}
|
||||
}
|
||||
|
||||
public static async refreshToken() {
|
||||
return this.instance
|
||||
.post<{ accessToken: string; expiresIn: number }>(`/auth/refresh`, {
|
||||
refreshToken: this.userAuth.refreshToken,
|
||||
})
|
||||
.then((response) => response.data);
|
||||
}
|
||||
|
||||
private static async revalidateAccessTokenIfExpired() {
|
||||
const now = new Date();
|
||||
|
||||
if (this.userAuth.expirationTimestamp < now.getTime()) {
|
||||
try {
|
||||
const response = await this.instance.post(`/auth/refresh`, {
|
||||
refreshToken: this.userAuth.refreshToken,
|
||||
});
|
||||
|
||||
const { accessToken, expiresIn } = response.data;
|
||||
const { accessToken, expiresIn } = await this.refreshToken();
|
||||
|
||||
const tokenExpirationTimestamp =
|
||||
now.getTime() +
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue