fix and update
This commit is contained in:
@@ -14,14 +14,38 @@ export function parsePopupOAuthParams(searchParams: URLSearchParams) {
|
||||
}
|
||||
}
|
||||
|
||||
export function postOneTapResult(popupOrigin: string, payload: Record<string, unknown>) {
|
||||
if (!window.opener) {
|
||||
export function postOneTapResult(popupOrigin: string, payload: Record<string, unknown>): boolean {
|
||||
if (!window.opener || window.opener.closed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
window.opener.postMessage({ type: ONE_TAP_MESSAGE_TYPE, ...payload }, popupOrigin);
|
||||
window.close();
|
||||
return true;
|
||||
try {
|
||||
window.opener.postMessage({ type: ONE_TAP_MESSAGE_TYPE, ...payload }, popupOrigin);
|
||||
window.close();
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function deliverOAuthPopupResult(
|
||||
popupContext: { popupOrigin: string } | null,
|
||||
redirectUrl: string
|
||||
): 'popup' | 'redirect' {
|
||||
if (!popupContext) {
|
||||
return 'redirect';
|
||||
}
|
||||
|
||||
const parsed = parseAuthorizationRedirect(redirectUrl);
|
||||
const delivered = postOneTapResult(popupContext.popupOrigin, {
|
||||
code: parsed.code ?? undefined,
|
||||
state: parsed.state ?? undefined,
|
||||
token: parsed.code ?? undefined,
|
||||
error: parsed.error ?? undefined,
|
||||
errorDescription: parsed.errorDescription ?? undefined
|
||||
});
|
||||
|
||||
return delivered ? 'popup' : 'redirect';
|
||||
}
|
||||
|
||||
export function parseAuthorizationRedirect(redirectUrl: string) {
|
||||
|
||||
Reference in New Issue
Block a user