mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-20 09:43:57 +00:00
feat: manage account buttons
This commit is contained in:
@@ -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() +
|
||||
|
||||
Reference in New Issue
Block a user