fix(core): let backend check whethere user can subscribe (#8573)
This commit is contained in:
@@ -16,7 +16,11 @@ import {
|
|||||||
RouteLogic,
|
RouteLogic,
|
||||||
useNavigateHelper,
|
useNavigateHelper,
|
||||||
} from '../../components/hooks/use-navigate-helper';
|
} from '../../components/hooks/use-navigate-helper';
|
||||||
import { AuthService, SubscriptionService } from '../../modules/cloud';
|
import {
|
||||||
|
AuthService,
|
||||||
|
BackendError,
|
||||||
|
SubscriptionService,
|
||||||
|
} from '../../modules/cloud';
|
||||||
import { container } from './subscribe.css';
|
import { container } from './subscribe.css';
|
||||||
|
|
||||||
interface ProductTriple {
|
interface ProductTriple {
|
||||||
@@ -113,6 +117,7 @@ export const Component = () => {
|
|||||||
await authService.session.waitForRevalidation(signal);
|
await authService.session.waitForRevalidation(signal);
|
||||||
const loggedIn =
|
const loggedIn =
|
||||||
authService.session.status$.value === 'authenticated';
|
authService.session.status$.value === 'authenticated';
|
||||||
|
|
||||||
if (!loggedIn) {
|
if (!loggedIn) {
|
||||||
setMessage('Redirecting to sign in...');
|
setMessage('Redirecting to sign in...');
|
||||||
jumpToSignIn(
|
jumpToSignIn(
|
||||||
@@ -121,17 +126,7 @@ export const Component = () => {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setMessage('Checking subscription status...');
|
setMessage('Checkout...');
|
||||||
await subscriptionService.subscription.waitForRevalidation(signal);
|
|
||||||
const subscribed =
|
|
||||||
plan === SubscriptionPlan.AI
|
|
||||||
? !!subscriptionService.subscription.ai$.value
|
|
||||||
: recurring === SubscriptionRecurring.Lifetime
|
|
||||||
? !!subscriptionService.subscription.isBeliever$.value
|
|
||||||
: !!subscriptionService.subscription.pro$.value;
|
|
||||||
|
|
||||||
if (!subscribed) {
|
|
||||||
setMessage('Creating checkout...');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const account = authService.session.account$.value;
|
const account = authService.session.account$.value;
|
||||||
@@ -159,15 +154,12 @@ export const Component = () => {
|
|||||||
setMessage('Redirecting...');
|
setMessage('Redirecting...');
|
||||||
location.href = checkout;
|
location.href = checkout;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
if (err instanceof BackendError) {
|
||||||
setError('Something went wrong. Please try again.');
|
setMessage(err.originError.message);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
setMessage('Your account is already subscribed. Redirecting...');
|
console.log(err);
|
||||||
await new Promise(resolve => {
|
setError('Something went wrong, please contact support.');
|
||||||
setTimeout(resolve, 5000);
|
}
|
||||||
});
|
|
||||||
jumpToIndex(RouteLogic.REPLACE);
|
|
||||||
}
|
}
|
||||||
}).pipe(mergeMap(() => EMPTY));
|
}).pipe(mergeMap(() => EMPTY));
|
||||||
})
|
})
|
||||||
@@ -191,10 +183,6 @@ export const Component = () => {
|
|||||||
coupon,
|
coupon,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
authService.session.revalidate();
|
|
||||||
}, [authService]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={container}>
|
<div className={container}>
|
||||||
{!error ? (
|
{!error ? (
|
||||||
|
|||||||
Reference in New Issue
Block a user