Skip to content

Commit

Permalink
fix: check for blank email address on magic links (#221)
Browse files Browse the repository at this point in the history
* check for blank email address on magic links

* Add changeset file to bump the package version

---------

Co-authored-by: Andrew Smith <[email protected]>
  • Loading branch information
Hallidayo and silentworks authored Sep 17, 2023
1 parent 5607ea4 commit 2b25291
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/pretty-pumpkins-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@supabase/auth-ui-shared': patch
'@supabase/auth-ui-react': patch
---

Fix check for blank email address on magic links
11 changes: 9 additions & 2 deletions packages/react/src/components/Auth/interfaces/MagicLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ function MagicLink({
setError('')
setMessage('')
setLoading(true)

if (email.length === 0) {
setError(i18n?.magic_link?.empty_email_address as string)
setLoading(false)
return
}
const { error } = await supabaseClient.auth.signInWithOtp({
email,
options: { emailRedirectTo: redirectTo },
Expand All @@ -60,9 +66,10 @@ function MagicLink({
type="email"
autoFocus
placeholder={labels?.email_input_placeholder}
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
if (setError) setError('')
setEmail(e.target.value)
}
}}
appearance={appearance}
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export type I18nVariables = {
loading_button_label?: string
link_text?: string
confirmation_text?: string
empty_email_address?: string
}
forgotten_password?: {
email_label?: string
Expand Down

0 comments on commit 2b25291

Please sign in to comment.