Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/platform/src/shared/components/auth/SocialAuthSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ const SOCIAL_PROVIDERS: Array<{
},
];

const LOCAL_TEST_HOSTNAMES = new Set([
'localhost',
'127.0.0.1',
'::1',
'0.0.0.0',
]);

const shouldShowSocialAuth = (hostname: string): boolean => {
const normalizedHostname = hostname.toLowerCase();

return (
normalizedHostname === 'staging' ||
normalizedHostname.startsWith('staging.') ||
LOCAL_TEST_HOSTNAMES.has(normalizedHostname)
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
};

export default function SocialAuthSection({
mode,
disabled = false,
Expand All @@ -59,10 +76,12 @@ export default function SocialAuthSection({
}: SocialAuthSectionProps) {
const actionLabel = mode === 'register' ? 'Continue with' : 'Sign in with';
const redirectPath = normalizeCallbackUrl(callbackUrl) || '/user/home';
const [isStagingDomain, setIsStagingDomain] = useState(false);
const [lastUsedProvider, setLastUsedProvider] =
useState<SupportedSocialAuthProvider | null>(null);

useEffect(() => {
setIsStagingDomain(shouldShowSocialAuth(window.location.hostname));
setLastUsedProvider(getLastUsedOAuthProvider());
}, []);

Expand Down Expand Up @@ -97,6 +116,10 @@ export default function SocialAuthSection({
[disabled, redirectPath]
);

if (!isStagingDomain) {
return null;
}

return (
<div className={cn('w-full space-y-2.5', className)}>
<div className="flex items-center gap-4">
Expand Down
17 changes: 13 additions & 4 deletions src/platform/src/shared/lib/paddle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ export const PADDLE_CHECKOUT_COMPLETED_EVENT =
'airqo:paddle-checkout-completed';
export const PADDLE_CHECKOUT_CLOSED_EVENT = 'airqo:paddle-checkout-closed';

export const getPaddleEnvironment = (): 'sandbox' | undefined =>
process.env.NEXT_PUBLIC_PAYMENT_ENVIRONMENT?.trim() === 'sandbox'
? 'sandbox'
: undefined;
export const getPaddleEnvironment = ():
| 'sandbox'
| 'production'
| undefined => {
const environment =
process.env.NEXT_PUBLIC_PAYMENT_ENVIRONMENT?.trim().toLowerCase();

if (environment === 'sandbox' || environment === 'production') {
return environment;
}

return undefined;
};

export const getPaymentClientToken = (): string =>
process.env.NEXT_PUBLIC_PAYMENT_CLIENT_TOKEN?.trim() || '';
11 changes: 10 additions & 1 deletion src/platform/src/shared/providers/paddle-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ const PaddleProvider = () => {
return;
}

const paddleWithEnvironment = paddle as typeof paddle & {
Environment?: {
set?: (environment: 'sandbox' | 'production') => void;
};
};

if (paddleEnvironment && paddleWithEnvironment.Environment?.set) {
paddleWithEnvironment.Environment.set(paddleEnvironment);
}

paddle.Initialize({
token: paymentClientToken,
...(paddleEnvironment ? { environment: paddleEnvironment } : {}),
eventCallback: event => {
if (event.name === 'checkout.completed') {
window.dispatchEvent(new Event(PADDLE_CHECKOUT_COMPLETED_EVENT));
Expand Down
Loading