From 5928f1f24f8da25b27174dc9045aed61b0d0fc68 Mon Sep 17 00:00:00 2001 From: Artyom Date: Mon, 29 May 2023 05:08:18 +0400 Subject: [PATCH] feat: Enhance actions based on current view This commit enhances the capability to perform additional actions based on the current view. It allows for customized actions, such as displaying messages, logging events, and hiding/displaying components, depending on the view. This improvement provides greater flexibility and customization options for different page states. --- packages/react/src/components/Auth/Auth.tsx | 9 +++++++++ packages/react/src/types.ts | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/react/src/components/Auth/Auth.tsx b/packages/react/src/components/Auth/Auth.tsx index 6c5234bc..a584e776 100644 --- a/packages/react/src/components/Auth/Auth.tsx +++ b/packages/react/src/components/Auth/Auth.tsx @@ -30,6 +30,7 @@ function Auth({ otpType = 'email', additionalData, children, + onViewChange, }: AuthProps): JSX.Element | null { /** * Localization support @@ -120,6 +121,14 @@ function Auth({ return () => authListener.subscription.unsubscribe() }, [view]) + useEffect(() => { + if (typeof onViewChange !== 'function') { + return; + } + + onViewChange(authView); + }, [authView]); + const emailProp: Omit = { supabaseClient, setAuthView, diff --git a/packages/react/src/types.ts b/packages/react/src/types.ts index 54ac3fb0..10b613be 100644 --- a/packages/react/src/types.ts +++ b/packages/react/src/types.ts @@ -1,4 +1,4 @@ -import { BaseAppearance, BaseAuth } from '@supabase/auth-ui-shared' +import { BaseAppearance, BaseAuth, ViewType } from '@supabase/auth-ui-shared' import { CSSProperties, ReactNode } from 'react' export interface Appearance extends BaseAppearance { @@ -17,4 +17,5 @@ export interface Appearance extends BaseAppearance { export interface Auth extends BaseAuth { children?: ReactNode appearance?: Appearance + onViewChange?: (view: ViewType) => void }