Skip to content

Commit

Permalink
Update Svelte and React package with event listener for password reset (
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Smith authored Mar 1, 2023
1 parent cf66245 commit 121e88d
Show file tree
Hide file tree
Showing 24 changed files with 152 additions and 309 deletions.
6 changes: 6 additions & 0 deletions .changeset/calm-onions-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@supabase/auth-ui-solid': patch
'@supabase/auth-ui-svelte': patch
---

Add html input autofocus
6 changes: 6 additions & 0 deletions .changeset/lazy-nails-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@supabase/auth-ui-react': patch
'@supabase/auth-ui-svelte': patch
---

Add event listener to show update form on password reset
5 changes: 5 additions & 0 deletions .changeset/smooth-glasses-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@supabase/auth-ui-react': patch
---

Add full relative file names for ESM in Node
2 changes: 2 additions & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"types": "./dist/index.d.ts",
"type": "module",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.es.js",
"require": "./dist/index.cjs.js"
}
Expand Down
11 changes: 11 additions & 0 deletions packages/react/src/components/Auth/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,18 @@ function Auth({
/**
* Overrides the authview if it is changed externally
*/
const { data: authListener } = supabaseClient.auth.onAuthStateChange(
(event) => {
if (event === 'PASSWORD_RECOVERY') {
setAuthView('update_password')
} else if (event === 'USER_UPDATED') {
setAuthView('sign_in')
}
}
)
setAuthView(view)

return () => authListener.subscription.unsubscribe()
}, [view])

const emailProp: Omit<EmailAuthProps, 'authView' | 'id'> = {
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/Auth/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as Auth } from './Auth'
export * from './interfaces'
export { default as Auth } from './Auth.js'
export * from './interfaces/index.js'
49 changes: 10 additions & 39 deletions packages/react/src/components/Auth/interfaces/EmailAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import {
RedirectTo,
ViewSignUp,
ViewSignIn,
ViewsMap,
VIEWS,
ViewType,
merge,
en,
} from '@supabase/auth-ui-shared'
import { Appearance } from './../../../types'
import { Anchor, Button, Container, Input, Label, Message } from './../../UI'
import { createStitches, createTheme } from '@stitches/core'
import {
Anchor,
Button,
Container,
Input,
Label,
Message,
} from './../../UI/index.js'

export interface EmailAuthProps {
authView?: ViewSignIn | ViewSignUp
Expand All @@ -27,15 +31,6 @@ export interface EmailAuthProps {
magicLink?: boolean
i18n?: I18nVariables
appearance?: Appearance
theme?: 'default' | string
}

const VIEWS: ViewsMap = {
SIGN_IN: 'sign_in',
SIGN_UP: 'sign_up',
FORGOTTEN_PASSWORD: 'forgotten_password',
MAGIC_LINK: 'magic_link',
UPDATE_PASSWORD: 'update_password',
}

function EmailAuth({
Expand All @@ -51,7 +46,6 @@ function EmailAuth({
magicLink,
i18n,
appearance,
theme = 'default',
}: EmailAuthProps) {
const isMounted = useRef<boolean>(true)
const [email, setEmail] = useState(defaultEmail)
Expand All @@ -60,27 +54,15 @@ function EmailAuth({
const [loading, setLoading] = useState(false)
const [message, setMessage] = useState('')

// Setting default lang to english
i18n = merge(en, i18n ?? {})

useEffect(() => {
isMounted.current = true
setEmail(defaultEmail)
setPassword(defaultPassword)

if (theme !== 'default') {
createStitches({
theme: merge(
appearance?.theme?.default ?? {},
appearance?.variables?.default ?? {}
),
})
}

return () => {
isMounted.current = false
}
}, [authView, appearance])
}, [authView])

const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
Expand Down Expand Up @@ -137,17 +119,6 @@ function EmailAuth({
onSubmit={handleSubmit}
autoComplete={'on'}
style={{ width: '100%' }}
className={
theme !== 'default'
? createTheme(
merge(
// @ts-ignore
appearance?.theme[theme],
appearance?.variables?.[theme] ?? {}
)
)
: undefined
}
>
<Container direction="vertical" gap="large" appearance={appearance}>
<Container direction="vertical" gap="large" appearance={appearance}>
Expand Down
58 changes: 11 additions & 47 deletions packages/react/src/components/Auth/interfaces/ForgottenPassword.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { SupabaseClient } from '@supabase/supabase-js'
import React, { useEffect, useRef, useState } from 'react'
import {
VIEWS,
I18nVariables,
RedirectTo,
merge,
en,
} from '@supabase/auth-ui-shared'
import React, { useState } from 'react'
import { VIEWS, I18nVariables, RedirectTo } from '@supabase/auth-ui-shared'
import { Appearance } from '../../../types'
import { Anchor, Button, Container, Input, Label, Message } from './../../UI'
import { createStitches, createTheme } from '@stitches/core'
import {
Anchor,
Button,
Container,
Input,
Label,
Message,
} from './../../UI/index.js'

function ForgottenPassword({
setAuthView = () => {},
Expand All @@ -18,41 +18,19 @@ function ForgottenPassword({
i18n,
appearance,
showLinks = false,
theme = 'default',
}: {
setAuthView?: any
supabaseClient: SupabaseClient
redirectTo?: RedirectTo
i18n?: I18nVariables
appearance?: Appearance
showLinks?: boolean
theme?: 'default' | string
}) {
const isMounted = useRef<boolean>(true)
const [email, setEmail] = useState('')
const [error, setError] = useState('')
const [message, setMessage] = useState('')
const [loading, setLoading] = useState(false)

// Setting default lang to english
i18n = merge(en, i18n ?? {})

useEffect(() => {
isMounted.current = true
if (theme !== 'default') {
createStitches({
theme: merge(
appearance?.theme?.default ?? {},
appearance?.variables?.default ?? {}
),
})
}

return () => {
isMounted.current = false
}
}, [appearance])

const handlePasswordReset = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
setError('')
Expand All @@ -69,21 +47,7 @@ function ForgottenPassword({
const labels = i18n?.forgotten_password

return (
<form
id="auth-forgot-password"
onSubmit={handlePasswordReset}
className={
theme !== 'default'
? createTheme(
merge(
// @ts-ignore
appearance?.theme[theme],
appearance?.variables?.[theme] ?? {}
)
)
: undefined
}
>
<form id="auth-forgot-password" onSubmit={handlePasswordReset}>
<Container gap="large" direction="vertical" appearance={appearance}>
<Container gap="large" direction="vertical" appearance={appearance}>
<div>
Expand Down
58 changes: 11 additions & 47 deletions packages/react/src/components/Auth/interfaces/MagicLink.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { SupabaseClient } from '@supabase/supabase-js'
import React, { useEffect, useRef, useState } from 'react'
import {
VIEWS,
I18nVariables,
RedirectTo,
merge,
en,
} from '@supabase/auth-ui-shared'
import React, { useState } from 'react'
import { VIEWS, I18nVariables, RedirectTo } from '@supabase/auth-ui-shared'
import { Appearance } from '../../../types'
import { Anchor, Button, Container, Input, Label, Message } from './../../UI'
import { createStitches, createTheme } from '@stitches/core'
import {
Anchor,
Button,
Container,
Input,
Label,
Message,
} from './../../UI/index.js'

function MagicLink({
setAuthView = () => {},
Expand All @@ -18,41 +18,19 @@ function MagicLink({
i18n,
appearance,
showLinks = false,
theme = 'default',
}: {
setAuthView?: any
supabaseClient: SupabaseClient
redirectTo?: RedirectTo
i18n?: I18nVariables
appearance?: Appearance
showLinks?: boolean
theme?: 'default' | string
}) {
const isMounted = useRef<boolean>(true)
const [email, setEmail] = useState('')
const [error, setError] = useState('')
const [message, setMessage] = useState('')
const [loading, setLoading] = useState(false)

// Setting default lang to english
i18n = merge(en, i18n ?? {})

useEffect(() => {
isMounted.current = true
if (theme !== 'default') {
createStitches({
theme: merge(
appearance?.theme?.default ?? {},
appearance?.variables?.default ?? {}
),
})
}

return () => {
isMounted.current = false
}
}, [appearance])

const handleMagicLinkSignIn = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
setError('')
Expand All @@ -70,21 +48,7 @@ function MagicLink({
const labels = i18n?.magic_link

return (
<form
id="auth-magic-link"
onSubmit={handleMagicLinkSignIn}
className={
theme !== 'default'
? createTheme(
merge(
// @ts-ignore
appearance?.theme[theme],
appearance?.variables?.[theme] ?? {}
)
)
: undefined
}
>
<form id="auth-magic-link" onSubmit={handleMagicLinkSignIn}>
<Container gap="large" direction="vertical" appearance={appearance}>
<Container gap="large" direction="vertical" appearance={appearance}>
<div>
Expand Down
Loading

0 comments on commit 121e88d

Please sign in to comment.