UNPKG

@clerk/shared

Version:

Internal package utils used by the Clerk SDKs

58 lines (56 loc) 2.03 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const require_netlifyCacheHandler = require('../../netlifyCacheHandler.js'); const require_internal_clerk_js_constants = require('./constants.js'); //#region src/internal/clerk-js/queryParams.ts const _ClerkQueryParams = [ "__clerk_status", "__clerk_created_session", "__clerk_invitation_token", "__clerk_ticket", "__clerk_modal_state", "__clerk_handshake", "__clerk_handshake_nonce", "__clerk_help", require_netlifyCacheHandler.CLERK_NETLIFY_CACHE_BUST_PARAM, require_internal_clerk_js_constants.CLERK_SYNCED, require_internal_clerk_js_constants.CLERK_SATELLITE_URL, require_internal_clerk_js_constants.CLERK_SUFFIXED_COOKIES ]; /** * */ function getClerkQueryParam(param) { const val = new URL(window.location.href).searchParams.get(param); return val ? val : null; } /** * */ function removeClerkQueryParam(param) { const url = new URL(window.location.href); if (url.searchParams.has(param)) { url.searchParams.delete(param); window.history.replaceState(window.history.state, "", url); } } /** * Extracts and forwards Clerk query parameters from the current URL to a new URLSearchParams object. * This is useful when navigating between pages while preserving Clerk-specific query parameters. * * @param params - Optional URLSearchParams object to add the parameters to. If not provided, a new one will be created. * @returns A URLSearchParams object containing the forwarded Clerk parameters */ function forwardClerkQueryParams(params) { const currentSearchParams = new URLSearchParams(window.location.search); const newParams = params || new URLSearchParams(); for (const param of _ClerkQueryParams) { const value = currentSearchParams.get(param); if (value) newParams.set(param, value); } return newParams; } //#endregion exports.forwardClerkQueryParams = forwardClerkQueryParams; exports.getClerkQueryParam = getClerkQueryParam; exports.removeClerkQueryParam = removeClerkQueryParam; //# sourceMappingURL=queryParams.js.map