@thunderid/nextjs 0.2.4 → 0.3.0
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/cjs/client/components/presentation/SignIn/SignIn.cjs.map +1 -1
- package/dist/client/components/presentation/SignIn/SignIn.d.ts +1 -1
- package/dist/client/components/presentation/SignIn/SignIn.d.ts.map +1 -1
- package/dist/client/components/presentation/SignIn/SignIn.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignIn.cjs","names":["SignIn: FC<SignInProps>","useThunderID","normalizedError: Error","response: any","EmbeddedFlowType","ThunderIDRuntimeError","BaseSignIn"],"sources":["../../../../../../src/client/components/presentation/SignIn/SignIn.tsx"],"sourcesContent":["/**\n * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).\n *\n * WSO2 LLC. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\n'use client';\n\nimport {EmbeddedFlowComponent, EmbeddedFlowType, ThunderIDRuntimeError} from '@thunderid/node';\nimport {BaseSignIn, BaseSignInProps, normalizeFlowResponse, useTranslation} from '@thunderid/react';\nimport {FC, useEffect, useRef, useState} from 'react';\nimport useThunderID from '../../../contexts/ThunderID/useThunderID';\n\n/**\n * Props for the SignIn component.\n * Extends BaseSignInProps for full compatibility with the React BaseSignIn component\n */\nexport type SignInProps = Pick<BaseSignInProps, 'className' | 'onSuccess' | 'onError' | 'variant' | 'size'>;\n\n/**\n * A SignIn component for Next.js that provides native authentication flow.\n * This component delegates to the BaseSignIn from @thunderid/react. Unlike BaseSignUp,\n * BaseSignIn does not manage its own flow state, so this component initiates the flow\n * (using the server-action-backed `signIn`) and tracks `components`/`executionId` itself.\n */\nconst SignIn: FC<SignInProps> = ({size = 'medium', variant = 'outlined', onError, ...rest}: SignInProps) => {\n const {signIn, applicationId, scopes} = useThunderID();\n const {t} = useTranslation();\n\n const [components, setComponents] = useState<EmbeddedFlowComponent[]>([]);\n const [additionalData, setAdditionalData] = useState<Record<string, any>>({});\n const [executionId, setExecutionId] = useState<string | undefined>(undefined);\n const [isFlowInitialized, setIsFlowInitialized] = useState(false);\n const [flowError, setFlowError] = useState<Error | null>(null);\n const initializationAttemptedRef = useRef(false);\n // A fresh challenge token is required on every step to prevent replay attacks; the server\n // rotates it on each response, so it's tracked in a ref (not state) to avoid a stale value\n // from a closure captured before the previous response's state update committed.\n const challengeTokenRef = useRef<string | undefined>(undefined);\n\n const applyFlowResponse = (response: any): void => {\n const normalized = normalizeFlowResponse(response, t, {resolveTranslations: false});\n\n challengeTokenRef.current = response?.challengeToken ?? undefined;\n setExecutionId(normalized.executionId ?? undefined);\n setComponents(normalized.components);\n setAdditionalData(normalized.additionalData);\n };\n\n const handleFlowError = (error: unknown): void => {\n const normalizedError: Error = error instanceof Error ? error : new Error(String(error));\n\n setFlowError(normalizedError);\n onError?.(normalizedError);\n };\n\n useEffect(() => {\n if (initializationAttemptedRef.current || !signIn) {\n return;\n }\n\n initializationAttemptedRef.current = true;\n\n (async (): Promise<void> => {\n try {\n const response: any = await signIn(\n {\n applicationId,\n flowType: EmbeddedFlowType.Authentication,\n ...(scopes && {scopes}),\n },\n {},\n );\n\n // `response` is undefined when the provider already redirected\n // (OAuth-redirect or completed flows are handled there directly).\n if (response) {\n applyFlowResponse(response);\n }\n } catch (error) {\n handleFlowError(error);\n } finally {\n setIsFlowInitialized(true);\n }\n })();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [signIn]);\n\n const handleOnSubmit = async (payload: any): Promise<void> => {\n if (!signIn) {\n throw new ThunderIDRuntimeError(\n '`signIn` function is not available.',\n 'SignIn-handleOnSubmit-RuntimeError-001',\n 'nextjs',\n );\n }\n\n const response: any = await signIn(\n {\n ...payload,\n executionId,\n ...(challengeTokenRef.current ? {challengeToken: challengeTokenRef.current} : {}),\n },\n {},\n );\n\n if (response) {\n applyFlowResponse(response);\n }\n };\n\n return (\n <BaseSignIn\n additionalData={additionalData}\n components={components}\n error={flowError}\n isLoading={!isFlowInitialized}\n onError={onError}\n onSubmit={handleOnSubmit}\n size={size}\n variant={variant}\n {...rest}\n />\n );\n};\n\nSignIn.displayName = 'SignIn';\n\nexport default SignIn;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqCA,MAAMA,UAA2B,EAAC,OAAO,UAAU,UAAU,YAAY,QAAS,GAAG,WAAuB;CAC1G,MAAM,EAAC,QAAQ,eAAe,WAAUC,8BAAc;CACtD,MAAM,EAAC,6CAAqB;CAE5B,MAAM,CAAC,YAAY,qCAAmD,EAAE,CAAC;CACzE,MAAM,CAAC,gBAAgB,yCAAmD,EAAE,CAAC;CAC7E,MAAM,CAAC,aAAa,sCAA+C,OAAU;CAC7E,MAAM,CAAC,mBAAmB,4CAAiC,MAAM;CACjE,MAAM,CAAC,WAAW,oCAAuC,KAAK;CAC9D,MAAM,+CAAoC,MAAM;CAIhD,MAAM,sCAA+C,OAAU;CAE/D,MAAM,qBAAqB,aAAwB;EACjD,MAAM,0DAAmC,UAAU,GAAG,EAAC,qBAAqB,OAAM,CAAC;AAEnF,oBAAkB,UAAU,UAAU,kBAAkB;AACxD,iBAAe,WAAW,eAAe,OAAU;AACnD,gBAAc,WAAW,WAAW;AACpC,oBAAkB,WAAW,eAAe;;CAG9C,MAAM,mBAAmB,UAAyB;EAChD,MAAMC,kBAAyB,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;AAExF,eAAa,gBAAgB;AAC7B,YAAU,gBAAgB;;AAG5B,4BAAgB;AACd,MAAI,2BAA2B,WAAW,CAAC,OACzC;AAGF,6BAA2B,UAAU;AAErC,GAAC,YAA2B;AAC1B,OAAI;IACF,MAAMC,WAAgB,MAAM,OAC1B;KACE;KACA,UAAUC,kCAAiB;KAC3B,GAAI,UAAU,EAAC,QAAO;KACvB,EACD,EAAE,CACH;AAID,QAAI,SACF,mBAAkB,SAAS;YAEtB,OAAO;AACd,oBAAgB,MAAM;aACd;AACR,yBAAqB,KAAK;;MAE1B;IAEH,CAAC,OAAO,CAAC;CAEZ,MAAM,iBAAiB,OAAO,YAAgC;AAC5D,MAAI,CAAC,OACH,OAAM,IAAIC,uCACR,uCACA,0CACA,SACD;EAGH,MAAMF,WAAgB,MAAM,OAC1B;GACE,GAAG;GACH;GACA,GAAI,kBAAkB,UAAU,EAAC,gBAAgB,kBAAkB,SAAQ,GAAG,EAAE;GACjF,EACD,EAAE,CACH;AAED,MAAI,SACF,mBAAkB,SAAS;;AAI/B,QACE,2CAACG;EACiB;EACJ;EACZ,OAAO;EACP,WAAW,CAAC;EACH;EACT,UAAU;EACJ;EACG;EACT,GAAI;GACJ;;AAIN,OAAO,cAAc;AAErB,qBAAe"}
|
|
1
|
+
{"version":3,"file":"SignIn.cjs","names":["SignIn: FC<SignInProps>","useThunderID","normalizedError: Error","response: any","EmbeddedFlowType","ThunderIDRuntimeError","BaseSignIn"],"sources":["../../../../../../src/client/components/presentation/SignIn/SignIn.tsx"],"sourcesContent":["/**\n * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).\n *\n * WSO2 LLC. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\n'use client';\n\nimport {EmbeddedFlowComponent, EmbeddedFlowType, ThunderIDRuntimeError} from '@thunderid/node';\nimport {BaseSignIn, BaseSignInProps, normalizeFlowResponse, useTranslation} from '@thunderid/react';\nimport {FC, useEffect, useRef, useState} from 'react';\nimport useThunderID from '../../../contexts/ThunderID/useThunderID';\n\n/**\n * Props for the SignIn component.\n * Extends BaseSignInProps for full compatibility with the React BaseSignIn component\n */\nexport type SignInProps = Pick<BaseSignInProps, 'className' | 'id' | 'onSuccess' | 'onError' | 'variant' | 'size'>;\n\n/**\n * A SignIn component for Next.js that provides native authentication flow.\n * This component delegates to the BaseSignIn from @thunderid/react. Unlike BaseSignUp,\n * BaseSignIn does not manage its own flow state, so this component initiates the flow\n * (using the server-action-backed `signIn`) and tracks `components`/`executionId` itself.\n */\nconst SignIn: FC<SignInProps> = ({size = 'medium', variant = 'outlined', onError, ...rest}: SignInProps) => {\n const {signIn, applicationId, scopes} = useThunderID();\n const {t} = useTranslation();\n\n const [components, setComponents] = useState<EmbeddedFlowComponent[]>([]);\n const [additionalData, setAdditionalData] = useState<Record<string, any>>({});\n const [executionId, setExecutionId] = useState<string | undefined>(undefined);\n const [isFlowInitialized, setIsFlowInitialized] = useState(false);\n const [flowError, setFlowError] = useState<Error | null>(null);\n const initializationAttemptedRef = useRef(false);\n // A fresh challenge token is required on every step to prevent replay attacks; the server\n // rotates it on each response, so it's tracked in a ref (not state) to avoid a stale value\n // from a closure captured before the previous response's state update committed.\n const challengeTokenRef = useRef<string | undefined>(undefined);\n\n const applyFlowResponse = (response: any): void => {\n const normalized = normalizeFlowResponse(response, t, {resolveTranslations: false});\n\n challengeTokenRef.current = response?.challengeToken ?? undefined;\n setExecutionId(normalized.executionId ?? undefined);\n setComponents(normalized.components);\n setAdditionalData(normalized.additionalData);\n };\n\n const handleFlowError = (error: unknown): void => {\n const normalizedError: Error = error instanceof Error ? error : new Error(String(error));\n\n setFlowError(normalizedError);\n onError?.(normalizedError);\n };\n\n useEffect(() => {\n if (initializationAttemptedRef.current || !signIn) {\n return;\n }\n\n initializationAttemptedRef.current = true;\n\n (async (): Promise<void> => {\n try {\n const response: any = await signIn(\n {\n applicationId,\n flowType: EmbeddedFlowType.Authentication,\n ...(scopes && {scopes}),\n },\n {},\n );\n\n // `response` is undefined when the provider already redirected\n // (OAuth-redirect or completed flows are handled there directly).\n if (response) {\n applyFlowResponse(response);\n }\n } catch (error) {\n handleFlowError(error);\n } finally {\n setIsFlowInitialized(true);\n }\n })();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [signIn]);\n\n const handleOnSubmit = async (payload: any): Promise<void> => {\n if (!signIn) {\n throw new ThunderIDRuntimeError(\n '`signIn` function is not available.',\n 'SignIn-handleOnSubmit-RuntimeError-001',\n 'nextjs',\n );\n }\n\n const response: any = await signIn(\n {\n ...payload,\n executionId,\n ...(challengeTokenRef.current ? {challengeToken: challengeTokenRef.current} : {}),\n },\n {},\n );\n\n if (response) {\n applyFlowResponse(response);\n }\n };\n\n return (\n <BaseSignIn\n additionalData={additionalData}\n components={components}\n error={flowError}\n isLoading={!isFlowInitialized}\n onError={onError}\n onSubmit={handleOnSubmit}\n size={size}\n variant={variant}\n {...rest}\n />\n );\n};\n\nSignIn.displayName = 'SignIn';\n\nexport default SignIn;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAqCA,MAAMA,UAA2B,EAAC,OAAO,UAAU,UAAU,YAAY,QAAS,GAAG,WAAuB;CAC1G,MAAM,EAAC,QAAQ,eAAe,WAAUC,8BAAc;CACtD,MAAM,EAAC,6CAAqB;CAE5B,MAAM,CAAC,YAAY,qCAAmD,EAAE,CAAC;CACzE,MAAM,CAAC,gBAAgB,yCAAmD,EAAE,CAAC;CAC7E,MAAM,CAAC,aAAa,sCAA+C,OAAU;CAC7E,MAAM,CAAC,mBAAmB,4CAAiC,MAAM;CACjE,MAAM,CAAC,WAAW,oCAAuC,KAAK;CAC9D,MAAM,+CAAoC,MAAM;CAIhD,MAAM,sCAA+C,OAAU;CAE/D,MAAM,qBAAqB,aAAwB;EACjD,MAAM,0DAAmC,UAAU,GAAG,EAAC,qBAAqB,OAAM,CAAC;AAEnF,oBAAkB,UAAU,UAAU,kBAAkB;AACxD,iBAAe,WAAW,eAAe,OAAU;AACnD,gBAAc,WAAW,WAAW;AACpC,oBAAkB,WAAW,eAAe;;CAG9C,MAAM,mBAAmB,UAAyB;EAChD,MAAMC,kBAAyB,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;AAExF,eAAa,gBAAgB;AAC7B,YAAU,gBAAgB;;AAG5B,4BAAgB;AACd,MAAI,2BAA2B,WAAW,CAAC,OACzC;AAGF,6BAA2B,UAAU;AAErC,GAAC,YAA2B;AAC1B,OAAI;IACF,MAAMC,WAAgB,MAAM,OAC1B;KACE;KACA,UAAUC,kCAAiB;KAC3B,GAAI,UAAU,EAAC,QAAO;KACvB,EACD,EAAE,CACH;AAID,QAAI,SACF,mBAAkB,SAAS;YAEtB,OAAO;AACd,oBAAgB,MAAM;aACd;AACR,yBAAqB,KAAK;;MAE1B;IAEH,CAAC,OAAO,CAAC;CAEZ,MAAM,iBAAiB,OAAO,YAAgC;AAC5D,MAAI,CAAC,OACH,OAAM,IAAIC,uCACR,uCACA,0CACA,SACD;EAGH,MAAMF,WAAgB,MAAM,OAC1B;GACE,GAAG;GACH;GACA,GAAI,kBAAkB,UAAU,EAAC,gBAAgB,kBAAkB,SAAQ,GAAG,EAAE;GACjF,EACD,EAAE,CACH;AAED,MAAI,SACF,mBAAkB,SAAS;;AAI/B,QACE,2CAACG;EACiB;EACJ;EACZ,OAAO;EACP,WAAW,CAAC;EACH;EACT,UAAU;EACJ;EACG;EACT,GAAI;GACJ;;AAIN,OAAO,cAAc;AAErB,qBAAe"}
|
|
@@ -21,7 +21,7 @@ import { FC } from 'react';
|
|
|
21
21
|
* Props for the SignIn component.
|
|
22
22
|
* Extends BaseSignInProps for full compatibility with the React BaseSignIn component
|
|
23
23
|
*/
|
|
24
|
-
export type SignInProps = Pick<BaseSignInProps, 'className' | 'onSuccess' | 'onError' | 'variant' | 'size'>;
|
|
24
|
+
export type SignInProps = Pick<BaseSignInProps, 'className' | 'id' | 'onSuccess' | 'onError' | 'variant' | 'size'>;
|
|
25
25
|
/**
|
|
26
26
|
* A SignIn component for Next.js that provides native authentication flow.
|
|
27
27
|
* This component delegates to the BaseSignIn from @thunderid/react. Unlike BaseSignUp,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignIn.d.ts","sourceRoot":"","sources":["../../../../../src/client/components/presentation/SignIn/SignIn.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH,OAAO,EAAa,eAAe,EAAwC,MAAM,kBAAkB,CAAC;AACpG,OAAO,EAAC,EAAE,EAA8B,MAAM,OAAO,CAAC;AAGtD;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,eAAe,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"SignIn.d.ts","sourceRoot":"","sources":["../../../../../src/client/components/presentation/SignIn/SignIn.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH,OAAO,EAAa,eAAe,EAAwC,MAAM,kBAAkB,CAAC;AACpG,OAAO,EAAC,EAAE,EAA8B,MAAM,OAAO,CAAC;AAGtD;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,eAAe,EAAE,WAAW,GAAG,IAAI,GAAG,WAAW,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC,CAAC;AAEnH;;;;;GAKG;AACH,QAAA,MAAM,MAAM,EAAE,EAAE,CAAC,WAAW,CAmG3B,CAAC;AAIF,eAAe,MAAM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignIn.js","names":["SignIn: FC<SignInProps>","useThunderID","normalizedError: Error","response: any"],"sources":["../../../../../src/client/components/presentation/SignIn/SignIn.tsx"],"sourcesContent":["/**\n * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).\n *\n * WSO2 LLC. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\n'use client';\n\nimport {EmbeddedFlowComponent, EmbeddedFlowType, ThunderIDRuntimeError} from '@thunderid/node';\nimport {BaseSignIn, BaseSignInProps, normalizeFlowResponse, useTranslation} from '@thunderid/react';\nimport {FC, useEffect, useRef, useState} from 'react';\nimport useThunderID from '../../../contexts/ThunderID/useThunderID';\n\n/**\n * Props for the SignIn component.\n * Extends BaseSignInProps for full compatibility with the React BaseSignIn component\n */\nexport type SignInProps = Pick<BaseSignInProps, 'className' | 'onSuccess' | 'onError' | 'variant' | 'size'>;\n\n/**\n * A SignIn component for Next.js that provides native authentication flow.\n * This component delegates to the BaseSignIn from @thunderid/react. Unlike BaseSignUp,\n * BaseSignIn does not manage its own flow state, so this component initiates the flow\n * (using the server-action-backed `signIn`) and tracks `components`/`executionId` itself.\n */\nconst SignIn: FC<SignInProps> = ({size = 'medium', variant = 'outlined', onError, ...rest}: SignInProps) => {\n const {signIn, applicationId, scopes} = useThunderID();\n const {t} = useTranslation();\n\n const [components, setComponents] = useState<EmbeddedFlowComponent[]>([]);\n const [additionalData, setAdditionalData] = useState<Record<string, any>>({});\n const [executionId, setExecutionId] = useState<string | undefined>(undefined);\n const [isFlowInitialized, setIsFlowInitialized] = useState(false);\n const [flowError, setFlowError] = useState<Error | null>(null);\n const initializationAttemptedRef = useRef(false);\n // A fresh challenge token is required on every step to prevent replay attacks; the server\n // rotates it on each response, so it's tracked in a ref (not state) to avoid a stale value\n // from a closure captured before the previous response's state update committed.\n const challengeTokenRef = useRef<string | undefined>(undefined);\n\n const applyFlowResponse = (response: any): void => {\n const normalized = normalizeFlowResponse(response, t, {resolveTranslations: false});\n\n challengeTokenRef.current = response?.challengeToken ?? undefined;\n setExecutionId(normalized.executionId ?? undefined);\n setComponents(normalized.components);\n setAdditionalData(normalized.additionalData);\n };\n\n const handleFlowError = (error: unknown): void => {\n const normalizedError: Error = error instanceof Error ? error : new Error(String(error));\n\n setFlowError(normalizedError);\n onError?.(normalizedError);\n };\n\n useEffect(() => {\n if (initializationAttemptedRef.current || !signIn) {\n return;\n }\n\n initializationAttemptedRef.current = true;\n\n (async (): Promise<void> => {\n try {\n const response: any = await signIn(\n {\n applicationId,\n flowType: EmbeddedFlowType.Authentication,\n ...(scopes && {scopes}),\n },\n {},\n );\n\n // `response` is undefined when the provider already redirected\n // (OAuth-redirect or completed flows are handled there directly).\n if (response) {\n applyFlowResponse(response);\n }\n } catch (error) {\n handleFlowError(error);\n } finally {\n setIsFlowInitialized(true);\n }\n })();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [signIn]);\n\n const handleOnSubmit = async (payload: any): Promise<void> => {\n if (!signIn) {\n throw new ThunderIDRuntimeError(\n '`signIn` function is not available.',\n 'SignIn-handleOnSubmit-RuntimeError-001',\n 'nextjs',\n );\n }\n\n const response: any = await signIn(\n {\n ...payload,\n executionId,\n ...(challengeTokenRef.current ? {challengeToken: challengeTokenRef.current} : {}),\n },\n {},\n );\n\n if (response) {\n applyFlowResponse(response);\n }\n };\n\n return (\n <BaseSignIn\n additionalData={additionalData}\n components={components}\n error={flowError}\n isLoading={!isFlowInitialized}\n onError={onError}\n onSubmit={handleOnSubmit}\n size={size}\n variant={variant}\n {...rest}\n />\n );\n};\n\nSignIn.displayName = 'SignIn';\n\nexport default SignIn;\n"],"mappings":";;;;;;;;;;;;;;;;AAqCA,MAAMA,UAA2B,EAAC,OAAO,UAAU,UAAU,YAAY,QAAS,GAAG,WAAuB;CAC1G,MAAM,EAAC,QAAQ,eAAe,WAAUC,sBAAc;CACtD,MAAM,EAAC,MAAK,gBAAgB;CAE5B,MAAM,CAAC,YAAY,iBAAiB,SAAkC,EAAE,CAAC;CACzE,MAAM,CAAC,gBAAgB,qBAAqB,SAA8B,EAAE,CAAC;CAC7E,MAAM,CAAC,aAAa,kBAAkB,SAA6B,OAAU;CAC7E,MAAM,CAAC,mBAAmB,wBAAwB,SAAS,MAAM;CACjE,MAAM,CAAC,WAAW,gBAAgB,SAAuB,KAAK;CAC9D,MAAM,6BAA6B,OAAO,MAAM;CAIhD,MAAM,oBAAoB,OAA2B,OAAU;CAE/D,MAAM,qBAAqB,aAAwB;EACjD,MAAM,aAAa,sBAAsB,UAAU,GAAG,EAAC,qBAAqB,OAAM,CAAC;AAEnF,oBAAkB,UAAU,UAAU,kBAAkB;AACxD,iBAAe,WAAW,eAAe,OAAU;AACnD,gBAAc,WAAW,WAAW;AACpC,oBAAkB,WAAW,eAAe;;CAG9C,MAAM,mBAAmB,UAAyB;EAChD,MAAMC,kBAAyB,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;AAExF,eAAa,gBAAgB;AAC7B,YAAU,gBAAgB;;AAG5B,iBAAgB;AACd,MAAI,2BAA2B,WAAW,CAAC,OACzC;AAGF,6BAA2B,UAAU;AAErC,GAAC,YAA2B;AAC1B,OAAI;IACF,MAAMC,WAAgB,MAAM,OAC1B;KACE;KACA,UAAU,iBAAiB;KAC3B,GAAI,UAAU,EAAC,QAAO;KACvB,EACD,EAAE,CACH;AAID,QAAI,SACF,mBAAkB,SAAS;YAEtB,OAAO;AACd,oBAAgB,MAAM;aACd;AACR,yBAAqB,KAAK;;MAE1B;IAEH,CAAC,OAAO,CAAC;CAEZ,MAAM,iBAAiB,OAAO,YAAgC;AAC5D,MAAI,CAAC,OACH,OAAM,IAAI,sBACR,uCACA,0CACA,SACD;EAGH,MAAMA,WAAgB,MAAM,OAC1B;GACE,GAAG;GACH;GACA,GAAI,kBAAkB,UAAU,EAAC,gBAAgB,kBAAkB,SAAQ,GAAG,EAAE;GACjF,EACD,EAAE,CACH;AAED,MAAI,SACF,mBAAkB,SAAS;;AAI/B,QACE,oBAAC;EACiB;EACJ;EACZ,OAAO;EACP,WAAW,CAAC;EACH;EACT,UAAU;EACJ;EACG;EACT,GAAI;GACJ;;AAIN,OAAO,cAAc;AAErB,qBAAe"}
|
|
1
|
+
{"version":3,"file":"SignIn.js","names":["SignIn: FC<SignInProps>","useThunderID","normalizedError: Error","response: any"],"sources":["../../../../../src/client/components/presentation/SignIn/SignIn.tsx"],"sourcesContent":["/**\n * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).\n *\n * WSO2 LLC. licenses this file to you under the Apache License,\n * Version 2.0 (the \"License\"); you may not use this file except\n * in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing,\n * software distributed under the License is distributed on an\n * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n * KIND, either express or implied. See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\n\n'use client';\n\nimport {EmbeddedFlowComponent, EmbeddedFlowType, ThunderIDRuntimeError} from '@thunderid/node';\nimport {BaseSignIn, BaseSignInProps, normalizeFlowResponse, useTranslation} from '@thunderid/react';\nimport {FC, useEffect, useRef, useState} from 'react';\nimport useThunderID from '../../../contexts/ThunderID/useThunderID';\n\n/**\n * Props for the SignIn component.\n * Extends BaseSignInProps for full compatibility with the React BaseSignIn component\n */\nexport type SignInProps = Pick<BaseSignInProps, 'className' | 'id' | 'onSuccess' | 'onError' | 'variant' | 'size'>;\n\n/**\n * A SignIn component for Next.js that provides native authentication flow.\n * This component delegates to the BaseSignIn from @thunderid/react. Unlike BaseSignUp,\n * BaseSignIn does not manage its own flow state, so this component initiates the flow\n * (using the server-action-backed `signIn`) and tracks `components`/`executionId` itself.\n */\nconst SignIn: FC<SignInProps> = ({size = 'medium', variant = 'outlined', onError, ...rest}: SignInProps) => {\n const {signIn, applicationId, scopes} = useThunderID();\n const {t} = useTranslation();\n\n const [components, setComponents] = useState<EmbeddedFlowComponent[]>([]);\n const [additionalData, setAdditionalData] = useState<Record<string, any>>({});\n const [executionId, setExecutionId] = useState<string | undefined>(undefined);\n const [isFlowInitialized, setIsFlowInitialized] = useState(false);\n const [flowError, setFlowError] = useState<Error | null>(null);\n const initializationAttemptedRef = useRef(false);\n // A fresh challenge token is required on every step to prevent replay attacks; the server\n // rotates it on each response, so it's tracked in a ref (not state) to avoid a stale value\n // from a closure captured before the previous response's state update committed.\n const challengeTokenRef = useRef<string | undefined>(undefined);\n\n const applyFlowResponse = (response: any): void => {\n const normalized = normalizeFlowResponse(response, t, {resolveTranslations: false});\n\n challengeTokenRef.current = response?.challengeToken ?? undefined;\n setExecutionId(normalized.executionId ?? undefined);\n setComponents(normalized.components);\n setAdditionalData(normalized.additionalData);\n };\n\n const handleFlowError = (error: unknown): void => {\n const normalizedError: Error = error instanceof Error ? error : new Error(String(error));\n\n setFlowError(normalizedError);\n onError?.(normalizedError);\n };\n\n useEffect(() => {\n if (initializationAttemptedRef.current || !signIn) {\n return;\n }\n\n initializationAttemptedRef.current = true;\n\n (async (): Promise<void> => {\n try {\n const response: any = await signIn(\n {\n applicationId,\n flowType: EmbeddedFlowType.Authentication,\n ...(scopes && {scopes}),\n },\n {},\n );\n\n // `response` is undefined when the provider already redirected\n // (OAuth-redirect or completed flows are handled there directly).\n if (response) {\n applyFlowResponse(response);\n }\n } catch (error) {\n handleFlowError(error);\n } finally {\n setIsFlowInitialized(true);\n }\n })();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [signIn]);\n\n const handleOnSubmit = async (payload: any): Promise<void> => {\n if (!signIn) {\n throw new ThunderIDRuntimeError(\n '`signIn` function is not available.',\n 'SignIn-handleOnSubmit-RuntimeError-001',\n 'nextjs',\n );\n }\n\n const response: any = await signIn(\n {\n ...payload,\n executionId,\n ...(challengeTokenRef.current ? {challengeToken: challengeTokenRef.current} : {}),\n },\n {},\n );\n\n if (response) {\n applyFlowResponse(response);\n }\n };\n\n return (\n <BaseSignIn\n additionalData={additionalData}\n components={components}\n error={flowError}\n isLoading={!isFlowInitialized}\n onError={onError}\n onSubmit={handleOnSubmit}\n size={size}\n variant={variant}\n {...rest}\n />\n );\n};\n\nSignIn.displayName = 'SignIn';\n\nexport default SignIn;\n"],"mappings":";;;;;;;;;;;;;;;;AAqCA,MAAMA,UAA2B,EAAC,OAAO,UAAU,UAAU,YAAY,QAAS,GAAG,WAAuB;CAC1G,MAAM,EAAC,QAAQ,eAAe,WAAUC,sBAAc;CACtD,MAAM,EAAC,MAAK,gBAAgB;CAE5B,MAAM,CAAC,YAAY,iBAAiB,SAAkC,EAAE,CAAC;CACzE,MAAM,CAAC,gBAAgB,qBAAqB,SAA8B,EAAE,CAAC;CAC7E,MAAM,CAAC,aAAa,kBAAkB,SAA6B,OAAU;CAC7E,MAAM,CAAC,mBAAmB,wBAAwB,SAAS,MAAM;CACjE,MAAM,CAAC,WAAW,gBAAgB,SAAuB,KAAK;CAC9D,MAAM,6BAA6B,OAAO,MAAM;CAIhD,MAAM,oBAAoB,OAA2B,OAAU;CAE/D,MAAM,qBAAqB,aAAwB;EACjD,MAAM,aAAa,sBAAsB,UAAU,GAAG,EAAC,qBAAqB,OAAM,CAAC;AAEnF,oBAAkB,UAAU,UAAU,kBAAkB;AACxD,iBAAe,WAAW,eAAe,OAAU;AACnD,gBAAc,WAAW,WAAW;AACpC,oBAAkB,WAAW,eAAe;;CAG9C,MAAM,mBAAmB,UAAyB;EAChD,MAAMC,kBAAyB,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,MAAM,CAAC;AAExF,eAAa,gBAAgB;AAC7B,YAAU,gBAAgB;;AAG5B,iBAAgB;AACd,MAAI,2BAA2B,WAAW,CAAC,OACzC;AAGF,6BAA2B,UAAU;AAErC,GAAC,YAA2B;AAC1B,OAAI;IACF,MAAMC,WAAgB,MAAM,OAC1B;KACE;KACA,UAAU,iBAAiB;KAC3B,GAAI,UAAU,EAAC,QAAO;KACvB,EACD,EAAE,CACH;AAID,QAAI,SACF,mBAAkB,SAAS;YAEtB,OAAO;AACd,oBAAgB,MAAM;aACd;AACR,yBAAqB,KAAK;;MAE1B;IAEH,CAAC,OAAO,CAAC;CAEZ,MAAM,iBAAiB,OAAO,YAAgC;AAC5D,MAAI,CAAC,OACH,OAAM,IAAI,sBACR,uCACA,0CACA,SACD;EAGH,MAAMA,WAAgB,MAAM,OAC1B;GACE,GAAG;GACH;GACA,GAAI,kBAAkB,UAAU,EAAC,gBAAgB,kBAAkB,SAAQ,GAAG,EAAE;GACjF,EACD,EAAE,CACH;AAED,MAAI,SACF,mBAAkB,SAAS;;AAI/B,QACE,oBAAC;EACiB;EACJ;EACZ,OAAO;EACP,WAAW,CAAC;EACH;EACT,UAAU;EACJ;EACG;EACT,GAAI;GACJ;;AAIN,OAAO,cAAc;AAErB,qBAAe"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thunderid/nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Next.js SDK for ThunderID",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"thunderid",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"@types/react": "19.2.14",
|
|
41
41
|
"jose": "5.2.0",
|
|
42
42
|
"tslib": "2.8.1",
|
|
43
|
-
"@thunderid/node": "^0.
|
|
44
|
-
"@thunderid/react": "^0.
|
|
43
|
+
"@thunderid/node": "^0.4.0",
|
|
44
|
+
"@thunderid/react": "^0.4.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@thunderid/eslint-plugin": "0.0.2",
|