Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dry-camels-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@slashid/react": patch
---

Users re-authenticated via initialToken prop now emit the `PersonIdentified_v1` event.
2 changes: 1 addition & 1 deletion packages/react-primitives/src/components/text/text.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const text = recipe({
color: publicVariables.color.foreground,
margin: 0,
lineHeight: "100%",
whiteSpace: "pre-wrap"
whiteSpace: "pre-wrap",
},

variants: {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/dynamic-flow/handle-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export const HandleForm: React.FC<Props> = ({
values,
defaultValue,
parsedPhoneNumber,
showFactorsOnly
showFactorsOnly,
]);

const onSubmit: React.FormEventHandler<HTMLFormElement> = (e) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/components/form/authenticating/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ export function Authenticating({ children }: AuthenticatingTemplateProps) {

export type AuthenticatingProps = Pick<Props, "flowState">;

export const AuthenticatingImplementation = ({ flowState }: AuthenticatingProps) => {
export const AuthenticatingImplementation = ({
flowState,
}: AuthenticatingProps) => {
const factor = flowState.context.config.factor;
const attempt = useRef(1);
const isLoggingIn = useRef(false);
Expand Down
42 changes: 31 additions & 11 deletions packages/react/src/context/slash-id-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,31 @@
[anonymousUsersEnabled, storeAnonymousUser, storeUser]
);

/**
* In most cases user identification happens in `@slashid/slashid`
* during authentication, the exception are when users are
* "re-authenticated" using a stored token.
*
* In `@slashid/react` this happens in one of two scenarios:
* - Token is provided as `initialToken` prop
* - Token is discovered in storage i.e. `storage.getItem(STORAGE_TOKEN_KEY)`
*/
const identifyUser = useCallback(
(user: User | AnonymousUser | null) => {
if (user && analyticsEnabled) {
try {
// in all other cases the core SDK will handle this
// here we just recreate the user object based on the preexisting token
// no event is emitted on the SDK side because of that
sidRef.current?.getAnalytics().identify(user);
} catch {
// fail silently
}
}
},
[analyticsEnabled]
);

useEffect(() => {
if (state !== "loaded") {
return;
Expand All @@ -427,7 +452,11 @@
const isTokenValid = token && (await validateToken(token));
if (!isTokenValid) return null;

return createAndStoreUserFromToken(token);
const user = createAndStoreUserFromToken(token);

identifyUser(user);

return user;
};

const loginWithDirectID = async () => {
Expand Down Expand Up @@ -458,16 +487,7 @@

const user = createAndStoreUserFromToken(tokenFromStorage);

if (user && analyticsEnabled) {
try {
// in all other cases the core SDK will handle this
// here we just recreate the user object based on the preexisting token
// no event is emitted on the SDK side because of that
sidRef.current?.getAnalytics().identify(user);
} catch {
// fail silently
}
}
identifyUser(user);

return user;
};
Expand Down Expand Up @@ -552,7 +572,7 @@
__syncExternalState,
]);

return (

Check warning on line 575 in packages/react/src/context/slash-id-context.tsx

View workflow job for this annotation

GitHub Actions / bundle-size (20.9.0)

React Hook useEffect has a missing dependency: 'identifyUser'. Either include it or remove the dependency array

Check warning on line 575 in packages/react/src/context/slash-id-context.tsx

View workflow job for this annotation

GitHub Actions / build (20.9.0, react-nextjs)

React Hook useEffect has a missing dependency: 'identifyUser'. Either include it or remove the dependency array

Check warning on line 575 in packages/react/src/context/slash-id-context.tsx

View workflow job for this annotation

GitHub Actions / build (20.9.0, react-nextjs)

React Hook useEffect has a missing dependency: 'identifyUser'. Either include it or remove the dependency array

Check warning on line 575 in packages/react/src/context/slash-id-context.tsx

View workflow job for this annotation

GitHub Actions / build (20.9.0, react-nextjs)

React Hook useEffect has a missing dependency: 'identifyUser'. Either include it or remove the dependency array

Check warning on line 575 in packages/react/src/context/slash-id-context.tsx

View workflow job for this annotation

GitHub Actions / build (20.9.0, slashid-remix-impl)

React Hook useEffect has a missing dependency: 'identifyUser'. Either include it or remove the dependency array

Check warning on line 575 in packages/react/src/context/slash-id-context.tsx

View workflow job for this annotation

GitHub Actions / build (20.9.0, slashid-remix-impl)

React Hook useEffect has a missing dependency: 'identifyUser'. Either include it or remove the dependency array

Check warning on line 575 in packages/react/src/context/slash-id-context.tsx

View workflow job for this annotation

GitHub Actions / build (20.9.0, slashid-remix-impl)

React Hook useEffect has a missing dependency: 'identifyUser'. Either include it or remove the dependency array
<SlashIDContext.Provider value={contextValue}>
<ThemeRoot {...themeProps}>{children}</ThemeRoot>
</SlashIDContext.Provider>
Expand Down
Loading