@contember/react-client-tenant 2.1.0-alpha.21 → 2.1.0-alpha.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/development/src/components/forms/PasswordlessSignInForm.cjs +2 -2
- package/dist/development/src/components/forms/PasswordlessSignInForm.cjs.map +1 -1
- package/dist/development/src/components/forms/PasswordlessSignInForm.js +2 -2
- package/dist/development/src/components/forms/PasswordlessSignInForm.js.map +1 -1
- package/dist/development/src/components/forms/PasswordlessSignInInitForm.cjs +6 -1
- package/dist/development/src/components/forms/PasswordlessSignInInitForm.cjs.map +1 -1
- package/dist/development/src/components/forms/PasswordlessSignInInitForm.js +6 -1
- package/dist/development/src/components/forms/PasswordlessSignInInitForm.js.map +1 -1
- package/dist/development/src/components/idp/IDP.cjs +4 -4
- package/dist/development/src/components/idp/IDP.cjs.map +1 -1
- package/dist/development/src/components/idp/IDP.js +4 -4
- package/dist/development/src/components/idp/IDP.js.map +1 -1
- package/dist/development/src/internal/hooks/useInitIDPRedirect.cjs +3 -3
- package/dist/development/src/internal/hooks/useInitIDPRedirect.cjs.map +1 -1
- package/dist/development/src/internal/hooks/useInitIDPRedirect.js +3 -3
- package/dist/development/src/internal/hooks/useInitIDPRedirect.js.map +1 -1
- package/dist/development/src/internal/hooks/useRedirectToBacklink.cjs +9 -4
- package/dist/development/src/internal/hooks/useRedirectToBacklink.cjs.map +1 -1
- package/dist/development/src/internal/hooks/useRedirectToBacklink.js +9 -4
- package/dist/development/src/internal/hooks/useRedirectToBacklink.js.map +1 -1
- package/dist/production/src/components/forms/PasswordlessSignInForm.cjs +2 -2
- package/dist/production/src/components/forms/PasswordlessSignInForm.cjs.map +1 -1
- package/dist/production/src/components/forms/PasswordlessSignInForm.js +2 -2
- package/dist/production/src/components/forms/PasswordlessSignInForm.js.map +1 -1
- package/dist/production/src/components/forms/PasswordlessSignInInitForm.cjs +5 -0
- package/dist/production/src/components/forms/PasswordlessSignInInitForm.cjs.map +1 -1
- package/dist/production/src/components/forms/PasswordlessSignInInitForm.js +5 -0
- package/dist/production/src/components/forms/PasswordlessSignInInitForm.js.map +1 -1
- package/dist/production/src/components/idp/IDP.cjs +2 -2
- package/dist/production/src/components/idp/IDP.cjs.map +1 -1
- package/dist/production/src/components/idp/IDP.js +2 -2
- package/dist/production/src/components/idp/IDP.js.map +1 -1
- package/dist/production/src/internal/hooks/useInitIDPRedirect.cjs +3 -3
- package/dist/production/src/internal/hooks/useInitIDPRedirect.cjs.map +1 -1
- package/dist/production/src/internal/hooks/useInitIDPRedirect.js +3 -3
- package/dist/production/src/internal/hooks/useInitIDPRedirect.js.map +1 -1
- package/dist/production/src/internal/hooks/useRedirectToBacklink.cjs +9 -4
- package/dist/production/src/internal/hooks/useRedirectToBacklink.cjs.map +1 -1
- package/dist/production/src/internal/hooks/useRedirectToBacklink.js +9 -4
- package/dist/production/src/internal/hooks/useRedirectToBacklink.js.map +1 -1
- package/dist/types/components/forms/PasswordlessSignInForm.d.ts +1 -1
- package/dist/types/components/forms/PasswordlessSignInForm.d.ts.map +1 -1
- package/dist/types/components/forms/PasswordlessSignInInitForm.d.ts.map +1 -1
- package/dist/types/components/idp/IDP.d.ts +2 -1
- package/dist/types/components/idp/IDP.d.ts.map +1 -1
- package/dist/types/internal/hooks/useInitIDPRedirect.d.ts +2 -1
- package/dist/types/internal/hooks/useInitIDPRedirect.d.ts.map +1 -1
- package/dist/types/internal/hooks/useRedirectToBacklink.d.ts +3 -1
- package/dist/types/internal/hooks/useRedirectToBacklink.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/components/forms/PasswordlessSignInForm.tsx +4 -4
- package/src/components/forms/PasswordlessSignInInitForm.tsx +6 -0
- package/src/components/idp/IDP.tsx +3 -2
- package/src/internal/hooks/useInitIDPRedirect.ts +4 -3
- package/src/internal/hooks/useRedirectToBacklink.ts +11 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contember/react-client-tenant",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "2.1.0-alpha.
|
|
4
|
+
"version": "2.1.0-alpha.23",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/production/index.js",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"directory": "packages/react-client-tenant"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@contember/graphql-client-tenant": "2.1.0-alpha.
|
|
38
|
-
"@contember/react-client": "2.1.0-alpha.
|
|
39
|
-
"@contember/react-utils": "2.1.0-alpha.
|
|
37
|
+
"@contember/graphql-client-tenant": "2.1.0-alpha.23",
|
|
38
|
+
"@contember/react-client": "2.1.0-alpha.23",
|
|
39
|
+
"@contember/react-utils": "2.1.0-alpha.23",
|
|
40
40
|
"@radix-ui/primitive": "^1.1.0",
|
|
41
41
|
"@radix-ui/react-slot": "^1.1.0",
|
|
42
42
|
"graphql-ts-client-api": "^3.1.17"
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ReactElement, useCallback, useMemo } from 'react'
|
|
2
1
|
import * as TenantApi from '@contember/graphql-client-tenant'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { useSetSessionToken } from '@contember/react-client'
|
|
3
|
+
import { ReactElement, useCallback, useMemo } from 'react'
|
|
5
4
|
import { useForm } from '../../contexts'
|
|
6
5
|
import { SignInPasswordlessMutationResult, useSignInPasswordlessMutation } from '../../hooks'
|
|
7
6
|
import { useRedirectToBacklinkCallback } from '../../internal/hooks/useRedirectToBacklink'
|
|
8
|
-
import {
|
|
7
|
+
import { FormContextValue, FormError, FormState } from '../../types/forms'
|
|
8
|
+
import { TenantForm } from './TenantForm'
|
|
9
9
|
|
|
10
10
|
export type PasswordlessSignInFormValues = {
|
|
11
11
|
token: string
|
|
@@ -5,6 +5,7 @@ import { FormContextValue, FormError, FormState } from '../../types/forms'
|
|
|
5
5
|
import { useForm } from '../../contexts'
|
|
6
6
|
import { InitSignInPasswordlessMutationResult, useInitSignInPasswordlessMutation } from '../../hooks'
|
|
7
7
|
import { PASSWORDLESS_REQUEST_STORAGE_KEY } from '../../consts'
|
|
8
|
+
import { useSaveBacklink } from '../../internal/hooks/useRedirectToBacklink'
|
|
8
9
|
|
|
9
10
|
export type PasswordlessSignInInitFormValues = {
|
|
10
11
|
email: string
|
|
@@ -33,10 +34,15 @@ export const usePasswordlessSignInInitForm = useForm as () => PasswordlessSignIn
|
|
|
33
34
|
export const PasswordlessSignInInitForm = ({ children, onSuccess }: PasswordlessSignInInitFormProps) => {
|
|
34
35
|
|
|
35
36
|
const initSignIn = useInitSignInPasswordlessMutation()
|
|
37
|
+
const saveBacklink = useSaveBacklink({
|
|
38
|
+
storage: 'local',
|
|
39
|
+
})
|
|
40
|
+
|
|
36
41
|
return (
|
|
37
42
|
<TenantForm<PasswordlessSignInInitFormContextValue, InitSignInPasswordlessMutationResult>
|
|
38
43
|
onSuccess={res => {
|
|
39
44
|
localStorage.setItem(PASSWORDLESS_REQUEST_STORAGE_KEY, res.result.requestId)
|
|
45
|
+
saveBacklink()
|
|
40
46
|
onSuccess?.(res)
|
|
41
47
|
}}
|
|
42
48
|
errorMapping={errorToField}
|
|
@@ -11,9 +11,10 @@ export interface IDPProps {
|
|
|
11
11
|
onInitError?: (error: IDPInitError) => void
|
|
12
12
|
onResponseError?: (error: IDPResponseError) => void
|
|
13
13
|
expiration?: number
|
|
14
|
+
redirectUrl?: string
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export const IDP = ({ children, onResponseError, onInitError, onLogin, expiration }: IDPProps) => {
|
|
17
|
+
export const IDP = ({ children, onResponseError, onInitError, onLogin, expiration, redirectUrl }: IDPProps) => {
|
|
17
18
|
const hasOauthResponse = useMemo(() => {
|
|
18
19
|
const params = new URLSearchParams(window.location.search)
|
|
19
20
|
return params.has('state') && (params.has('code') || params.has('id_token'))
|
|
@@ -31,7 +32,7 @@ export const IDP = ({ children, onResponseError, onInitError, onLogin, expiratio
|
|
|
31
32
|
})
|
|
32
33
|
useHandleIDPResponse({ hasOauthResponse, setState, onLogin, expiration: expiration })
|
|
33
34
|
|
|
34
|
-
const initRedirect = useInitIDPRedirect({ setState })
|
|
35
|
+
const initRedirect = useInitIDPRedirect({ setState, redirectUrl })
|
|
35
36
|
|
|
36
37
|
const isFirstRender = useRef(true)
|
|
37
38
|
useEffect(() => {
|
|
@@ -8,9 +8,10 @@ import { useSaveBacklink } from './useRedirectToBacklink'
|
|
|
8
8
|
export interface UseInitIDPRedirectProps {
|
|
9
9
|
onRedirect?: (url: string) => void
|
|
10
10
|
setState: (state: SetStateAction<IDPStateValue>) => void
|
|
11
|
+
redirectUrl?: string
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
export const useInitIDPRedirect = ({ onRedirect, setState }: UseInitIDPRedirectProps) => {
|
|
14
|
+
export const useInitIDPRedirect = ({ onRedirect, setState, redirectUrl }: UseInitIDPRedirectProps) => {
|
|
14
15
|
const initRequest = useInitSignInIDPMutation()
|
|
15
16
|
const saveBacklink = useSaveBacklink()
|
|
16
17
|
const { set: saveIdpState } = useIDPStateStore()
|
|
@@ -24,7 +25,7 @@ export const useInitIDPRedirect = ({ onRedirect, setState }: UseInitIDPRedirectP
|
|
|
24
25
|
setState({ type: 'processing_init' })
|
|
25
26
|
const response = await initRequest({
|
|
26
27
|
data: {
|
|
27
|
-
redirectUrl: getBaseHref(),
|
|
28
|
+
redirectUrl: redirectUrl || getBaseHref(),
|
|
28
29
|
},
|
|
29
30
|
identityProvider: provider,
|
|
30
31
|
})
|
|
@@ -44,5 +45,5 @@ export const useInitIDPRedirect = ({ onRedirect, setState }: UseInitIDPRedirectP
|
|
|
44
45
|
console.error(e)
|
|
45
46
|
return fail('UNKNOWN_ERROR')
|
|
46
47
|
}
|
|
47
|
-
}, [initRequest, onRedirect, saveBacklink, saveIdpState, setState])
|
|
48
|
+
}, [initRequest, onRedirect, saveBacklink, saveIdpState, setState, redirectUrl])
|
|
48
49
|
}
|
|
@@ -5,23 +5,30 @@ const getBacklinkFromUrl = () => {
|
|
|
5
5
|
return new URLSearchParams(window.location.search).get('backlink')
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export const useSaveBacklink = (
|
|
8
|
+
export const useSaveBacklink = ({ storage = 'session' }: {
|
|
9
|
+
storage?: 'session' | 'local'
|
|
10
|
+
} = {}) => {
|
|
9
11
|
return useCallback(() => {
|
|
10
12
|
const backlink = getBacklinkFromUrl()
|
|
11
13
|
if (!backlink) {
|
|
12
14
|
return
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
if (storage === 'local') {
|
|
17
|
+
localStorage.setItem('backlink', backlink)
|
|
18
|
+
} else {
|
|
19
|
+
sessionStorage.setItem('backlink', backlink)
|
|
20
|
+
}
|
|
21
|
+
}, [storage])
|
|
16
22
|
}
|
|
17
23
|
|
|
18
24
|
export const useRedirectToBacklinkCallback = () => {
|
|
19
25
|
return useCallback(() => {
|
|
20
|
-
const backlink = getBacklinkFromUrl() ?? sessionStorage.getItem('backlink')
|
|
26
|
+
const backlink = getBacklinkFromUrl() ?? sessionStorage.getItem('backlink') ?? localStorage.getItem('backlink')
|
|
21
27
|
if (!backlink) {
|
|
22
28
|
return
|
|
23
29
|
}
|
|
24
30
|
sessionStorage.removeItem('backlink')
|
|
31
|
+
localStorage.removeItem('backlink')
|
|
25
32
|
const resolvedBacklink = new URL(backlink, window.location.href)
|
|
26
33
|
if (resolvedBacklink.origin === window.location.origin) {
|
|
27
34
|
window.location.href = resolvedBacklink.toString()
|