UNPKG

@progress/sitefinity-nextjs-sdk

Version:

Provides OOB widgets developed using the Next.js framework, which includes an abstraction layer for Sitefinity communication. Additionally, it offers an expanded API, typings, and tools for further development and integration.

72 lines (71 loc) 2.75 kB
'use client'; export class ExternalLoginBase { static ErrorQueryKey = 'loginerror'; static ShowSuccessMessageQueryKey = 'showSuccessMessage'; static ExternalLoginHandlerPath = '/sitefinity/external-login-handler'; static ShowSuccessMessageQueryParameter = false; static isError = (queryParams) => { if (queryParams && queryParams[this.ErrorQueryKey]) { return queryParams[this.ErrorQueryKey].toLowerCase() === 'true'; } return false; }; static GetDefaultReturnUrl(queryParams, args = { isError: false, shouldEncode: false }) { const searchParams = { ...queryParams }; delete searchParams[this.ErrorQueryKey]; delete searchParams[this.ShowSuccessMessageQueryKey]; if (args.isError) { searchParams[this.ErrorQueryKey] = args.isError ? 'True' : 'False'; } else if (this.ShowSuccessMessageQueryParameter) { searchParams[this.ShowSuccessMessageQueryKey] = 'True'; } if (typeof window !== 'undefined') { const queryString = new URLSearchParams(searchParams); let result = ''; if (args.redirectUrl) { result = args.redirectUrl; } else { result = window.location.href.replace(window.location.search, ''); } if (queryString && Array.from(queryString).length > 0) { result = `${result}?${queryString}`; } if (!ExternalLoginBase.isAbsoluteUrl(result)) { result = new URL(result, window.location.origin).toString(); } if (args.shouldEncode) { result = encodeURIComponent(result).toLowerCase(); } return result; } if (args.redirectUrl) { return args.redirectUrl; } return ''; } static GetExternalLoginPath(queryParams, provider, externalLoginHandlerPath) { const expandPath = externalLoginHandlerPath || this.ExternalLoginHandlerPath; const returnUrl = this.GetDefaultReturnUrl(queryParams, { isError: false, shouldEncode: true }); const errorUrl = this.GetDefaultReturnUrl(queryParams, { isError: true, shouldEncode: true }); return `${expandPath}?provider=${provider}&returnUrl=${returnUrl}&errorUrl=${errorUrl}`; } static GetExternalLoginButtonCssClass(provider) { if (!provider) { return ''; } return '-sf-' + provider.toLowerCase() + '-button'; } static isAbsoluteUrl(url) { try { new URL(url); return true; } catch (error) { return false; } } }