fix: user data not being correctly loaded on hydra api setup

This commit is contained in:
Zamitto
2024-12-20 14:48:04 -03:00
parent c8d1b2c19a
commit 170ac28bb5
3 changed files with 29 additions and 13 deletions

View File

@@ -23,7 +23,7 @@ interface HydraApiUserAuth {
authToken: string;
refreshToken: string;
expirationTimestamp: number;
subscription: { expiresAt: Date | null } | null;
subscription: { expiresAt: Date | string | null } | null;
}
export class HydraApi {
@@ -182,8 +182,6 @@ export class HydraApi {
);
}
await getUserData();
const userAuth = await userAuthRepository.findOne({
where: { id: 1 },
relations: { subscription: true },
@@ -197,6 +195,14 @@ export class HydraApi {
? { expiresAt: userAuth.subscription?.expiresAt }
: null,
};
const updatedUserData = await getUserData();
this.userAuth.subscription = updatedUserData?.subscription
? {
expiresAt: updatedUserData.subscription.expiresAt,
}
: null;
}
private static sendSignOutEvent() {
@@ -284,10 +290,8 @@ export class HydraApi {
await this.revalidateAccessTokenIfExpired();
}
if (needsSubscription) {
if (!(await this.hasActiveSubscription())) {
throw new SubscriptionRequiredError();
}
if (needsSubscription && !this.hasActiveSubscription()) {
throw new SubscriptionRequiredError();
}
}