Skip to content

Commit

Permalink
feat(auth): reload subscriptions, transactions and payment parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristiaanScheermeijer committed May 23, 2022
1 parent cfc82ec commit 8b526b0
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/stores/AccountController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,7 @@ export const afterLogin = async (sandbox: boolean, auth: AuthData) => {
user: response.responseData,
});

if (accessModel === 'SVOD') {
await reloadActiveSubscription();
}

await getCustomerConsents();
await getPublisherConsents();
await Promise.allSettled([accessModel === 'SVOD' ? reloadActiveSubscription() : Promise.resolve(), getCustomerConsents(), getPublisherConsents()]);

useAccountStore.setState({ loading: false });
};
Expand Down Expand Up @@ -301,6 +296,7 @@ export const updateCaptureAnswers = async (capture: Capture) => {

if (response.errors.length > 0) throw new Error(response.errors[0]);

// @todo why is this needed?
await afterLogin(cleengSandbox, auth);

return response.responseData;
Expand Down Expand Up @@ -369,9 +365,11 @@ export async function reloadActiveSubscription({ delay }: { delay: number } = {
useAccountStore.setState({ loading: true });

return await useLoginContext(async ({ cleengSandbox, customerId, auth: { jwt } }) => {
const activeSubscription = await getActiveSubscription({ cleengSandbox, customerId, jwt });
const transactions = await getAllTransactions({ cleengSandbox, customerId, jwt });
const activePayment = await getActivePayment({ cleengSandbox, customerId, jwt });
const [activeSubscription, transactions, activePayment] = await Promise.all([
getActiveSubscription({ cleengSandbox, customerId, jwt }),
getAllTransactions({ cleengSandbox, customerId, jwt }),
getActivePayment({ cleengSandbox, customerId, jwt }),
]);

// The subscription data takes a few seconds to load after it's purchased,
// so here's a delay mechanism to give it time to process
Expand Down

0 comments on commit 8b526b0

Please sign in to comment.