diff --git a/packages/app/@typing/Settings.d.ts b/packages/app/@typing/Settings.d.ts index 8b63a30..37818ab 100644 --- a/packages/app/@typing/Settings.d.ts +++ b/packages/app/@typing/Settings.d.ts @@ -21,6 +21,11 @@ declare module 'App' { * Read more at {@link https://docs.commercelayer.io/core/authentication/client-credentials#password}, {@link https://docs.commercelayer.io/core/authentication/password} */ customerAccessToken?: string + /** + * Access Token expiry date for a sales channel API credentials obtained using login password flow. + * Read more at {@link https://docs.commercelayer.io/core/authentication/client-credentials#password}, {@link https://docs.commercelayer.io/core/authentication/password} + */ + customerAccessTokenExpires?: string /** * Organization slug. * Read more at {@link https://docs.commercelayer.io/core/v/api-reference/organization/object}. diff --git a/packages/app/src/components/forms/LoginForm.tsx b/packages/app/src/components/forms/LoginForm.tsx index 6b93b16..0473eca 100644 --- a/packages/app/src/components/forms/LoginForm.tsx +++ b/packages/app/src/components/forms/LoginForm.tsx @@ -50,8 +50,9 @@ export const LoginForm = (): JSX.Element => { .then((tokenData) => { if (tokenData.accessToken != null) { redirectToReturnUrl({ + scope: tokenData.scope, accessToken: tokenData.accessToken, - scope: tokenData.scope + expires: tokenData.expires.toISOString() }) } else { form.setError('root', { diff --git a/packages/app/src/components/forms/SignUpForm.tsx b/packages/app/src/components/forms/SignUpForm.tsx index 869833c..f3d65a7 100644 --- a/packages/app/src/components/forms/SignUpForm.tsx +++ b/packages/app/src/components/forms/SignUpForm.tsx @@ -73,8 +73,9 @@ export const SignUpForm = (): JSX.Element => { .then((tokenData) => { if (tokenData.accessToken != null) { redirectToReturnUrl({ + scope: tokenData.scope, accessToken: tokenData.accessToken, - scope: tokenData.scope + expires: tokenData.expires.toISOString() }) } }) diff --git a/packages/app/src/utils/redirectToReturnUrl.ts b/packages/app/src/utils/redirectToReturnUrl.ts index be19213..89f8e81 100644 --- a/packages/app/src/utils/redirectToReturnUrl.ts +++ b/packages/app/src/utils/redirectToReturnUrl.ts @@ -4,8 +4,9 @@ import { getParamFromUrl } from '#utils/getParamFromUrl' import type { Settings } from 'App' interface RedirectToReturnUrlConfig { - accessToken: Settings['accessToken'] scope: Settings['scope'] + accessToken: Settings['customerAccessToken'] + expires: Settings['customerAccessTokenExpires'] } /** @@ -15,8 +16,9 @@ interface RedirectToReturnUrlConfig { * @param scope - String specified during the authentication flow to restrict the scope of obtained access token to a market and/or to a stock location. */ export const redirectToReturnUrl = ({ + scope, accessToken, - scope + expires }: RedirectToReturnUrlConfig): void => { const returnUrl = getParamFromUrl('returnUrl') if (returnUrl != null && window !== undefined) { @@ -24,6 +26,9 @@ export const redirectToReturnUrl = ({ const url = new URL(returnUrl) url.searchParams.append('accessToken', accessToken ?? '') url.searchParams.append('scope', scope) + if (expires != null) { + url.searchParams.append('expires', expires) + } topWindow.location.href = url.href } }