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
7 changes: 7 additions & 0 deletions packages/react/src/components/Auth/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function Auth({
otpType = 'email',
additionalData,
passwordLimit,
onViewChange,
children,
}: AuthProps): JSX.Element | null {
/**
Expand All @@ -42,6 +43,12 @@ function Auth({
const [defaultEmail, setDefaultEmail] = useState('')
const [defaultPassword, setDefaultPassword] = useState('')

useEffect(() => {
if (onViewChange) {
onViewChange(authView)
}
}, [authView, onViewChange])
Comment on lines +46 to +50
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid the useEffect by making a handleSetAuthView function and use it instead of setAuthView:

const handleSetAuthView = (view: ViewType) => {
  setAuthView(view);
  onViewChange?.(view);
};


/**
* Simple boolean to detect if authView 'sign_in' or 'sign_up' or 'magic_link' is used
*
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/types.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -17,4 +17,5 @@ export interface Appearance extends BaseAppearance {
export interface Auth extends BaseAuth {
children?: ReactNode
appearance?: Appearance
onViewChange?: (view: ViewType) => void
}