mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
refactor user preferences and create user auth entity
This commit is contained in:
parent
9e5118d1dc
commit
1797abb2da
5 changed files with 39 additions and 16 deletions
|
@ -11,6 +11,7 @@ import type { BetterSqlite3ConnectionOptions } from "typeorm/driver/better-sqlit
|
||||||
|
|
||||||
import { databasePath } from "./constants";
|
import { databasePath } from "./constants";
|
||||||
import migrations from "./migrations";
|
import migrations from "./migrations";
|
||||||
|
import { UserAuth } from "./entity/user-auth";
|
||||||
|
|
||||||
export const createDataSource = (
|
export const createDataSource = (
|
||||||
options: Partial<BetterSqlite3ConnectionOptions>
|
options: Partial<BetterSqlite3ConnectionOptions>
|
||||||
|
@ -24,6 +25,7 @@ export const createDataSource = (
|
||||||
GameShopCache,
|
GameShopCache,
|
||||||
DownloadSource,
|
DownloadSource,
|
||||||
DownloadQueue,
|
DownloadQueue,
|
||||||
|
UserAuth,
|
||||||
],
|
],
|
||||||
synchronize: true,
|
synchronize: true,
|
||||||
database: databasePath,
|
database: databasePath,
|
||||||
|
|
28
src/main/entity/user-auth.ts
Normal file
28
src/main/entity/user-auth.ts
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import {
|
||||||
|
Entity,
|
||||||
|
PrimaryGeneratedColumn,
|
||||||
|
Column,
|
||||||
|
CreateDateColumn,
|
||||||
|
UpdateDateColumn,
|
||||||
|
} from "typeorm";
|
||||||
|
|
||||||
|
@Entity("user_auth")
|
||||||
|
export class UserAuth {
|
||||||
|
@PrimaryGeneratedColumn()
|
||||||
|
id: number;
|
||||||
|
|
||||||
|
@Column("text", { default: "" })
|
||||||
|
accessToken: string;
|
||||||
|
|
||||||
|
@Column("text", { default: "" })
|
||||||
|
refreshToken: string;
|
||||||
|
|
||||||
|
@Column("int", { default: 0 })
|
||||||
|
tokenExpirationTimestamp: number;
|
||||||
|
|
||||||
|
@CreateDateColumn()
|
||||||
|
createdAt: Date;
|
||||||
|
|
||||||
|
@UpdateDateColumn()
|
||||||
|
updatedAt: Date;
|
||||||
|
}
|
|
@ -37,13 +37,4 @@ export class UserPreferences {
|
||||||
|
|
||||||
@UpdateDateColumn()
|
@UpdateDateColumn()
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
|
||||||
@Column("text", { default: "" })
|
|
||||||
accessToken: string;
|
|
||||||
|
|
||||||
@Column("text", { default: "" })
|
|
||||||
refreshToken: string;
|
|
||||||
|
|
||||||
@Column("int", { default: 0 })
|
|
||||||
tokenExpirationTimestamp: number;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
Repack,
|
Repack,
|
||||||
UserPreferences,
|
UserPreferences,
|
||||||
} from "@main/entity";
|
} from "@main/entity";
|
||||||
|
import { UserAuth } from "./entity/user-auth";
|
||||||
|
|
||||||
export const gameRepository = dataSource.getRepository(Game);
|
export const gameRepository = dataSource.getRepository(Game);
|
||||||
|
|
||||||
|
@ -21,3 +22,5 @@ export const downloadSourceRepository =
|
||||||
dataSource.getRepository(DownloadSource);
|
dataSource.getRepository(DownloadSource);
|
||||||
|
|
||||||
export const downloadQueueRepository = dataSource.getRepository(DownloadQueue);
|
export const downloadQueueRepository = dataSource.getRepository(DownloadQueue);
|
||||||
|
|
||||||
|
export const userAuthRepository = dataSource.getRepository(UserAuth);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { refreshTokenSchema } from "@main/events/helpers/validators";
|
import { userAuthRepository } from "@main/repository";
|
||||||
import { userPreferencesRepository } from "@main/repository";
|
|
||||||
import axios, { AxiosInstance } from "axios";
|
import axios, { AxiosInstance } from "axios";
|
||||||
|
|
||||||
export class HydraApi {
|
export class HydraApi {
|
||||||
|
@ -18,14 +17,14 @@ export class HydraApi {
|
||||||
baseURL: import.meta.env.MAIN_VITE_API_URL,
|
baseURL: import.meta.env.MAIN_VITE_API_URL,
|
||||||
});
|
});
|
||||||
|
|
||||||
const userPreferences = await userPreferencesRepository.findOne({
|
const userAuth = await userAuthRepository.findOne({
|
||||||
where: { id: 1 },
|
where: { id: 1 },
|
||||||
});
|
});
|
||||||
|
|
||||||
this.userAuth = {
|
this.userAuth = {
|
||||||
authToken: userPreferences?.accessToken ?? "",
|
authToken: userAuth?.accessToken ?? "",
|
||||||
refreshToken: userPreferences?.refreshToken ?? "",
|
refreshToken: userAuth?.refreshToken ?? "",
|
||||||
expirationTimestamp: userPreferences?.tokenExpirationTimestamp ?? 0,
|
expirationTimestamp: userAuth?.tokenExpirationTimestamp ?? 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +43,7 @@ export class HydraApi {
|
||||||
this.userAuth.authToken = accessToken;
|
this.userAuth.authToken = accessToken;
|
||||||
this.userAuth.expirationTimestamp = tokenExpirationTimestamp;
|
this.userAuth.expirationTimestamp = tokenExpirationTimestamp;
|
||||||
|
|
||||||
userPreferencesRepository.upsert(
|
userAuthRepository.upsert(
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
accessToken,
|
accessToken,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue