Skip to content

Commit

Permalink
Merge pull request #246 from Hallidayo/187-fix
Browse files Browse the repository at this point in the history
feat: password limit prop
  • Loading branch information
J0 authored Jan 30, 2024
2 parents 46f2be1 + 3521c08 commit a70f74d
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/react/src/components/Auth/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function Auth({
localization = { variables: {} },
otpType = 'email',
additionalData,
passwordLimit,
children,
}: AuthProps): JSX.Element | null {
/**
Expand Down Expand Up @@ -132,6 +133,7 @@ function Auth({
showLinks,
i18n,
appearance,
passwordLimit,
}

/**
Expand Down Expand Up @@ -162,6 +164,7 @@ function Auth({
showLinks={showLinks}
i18n={i18n}
additionalData={additionalData}
passwordLimit={passwordLimit}
children={children}
/>
</Container>
Expand Down Expand Up @@ -200,6 +203,7 @@ function Auth({
appearance={appearance}
supabaseClient={supabaseClient}
i18n={i18n}
passwordLimit={passwordLimit}
/>
)
case VIEWS.VERIFY_OTP:
Expand Down
6 changes: 6 additions & 0 deletions packages/react/src/components/Auth/interfaces/EmailAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface EmailAuthProps {
magicLink?: boolean
i18n?: I18nVariables
appearance?: Appearance
passwordLimit?: boolean
children?: React.ReactNode
}

Expand All @@ -49,6 +50,7 @@ function EmailAuth({
magicLink,
i18n,
appearance,
passwordLimit = false,
children,
}: EmailAuthProps) {
const isMounted = useRef<boolean>(true)
Expand Down Expand Up @@ -82,6 +84,10 @@ function EmailAuth({
if (signInError) setError(signInError.message)
break
case 'sign_up':
if (passwordLimit && password.length > 72) {
setError('Password exceeds maxmium length of 72 characters')
return
}
let options: { emailRedirectTo: RedirectTo; data?: object } = {
emailRedirectTo: redirectTo,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ function UpdatePassword({
supabaseClient,
i18n,
appearance,
passwordLimit = false,
}: {
supabaseClient: SupabaseClient
i18n?: I18nVariables
appearance?: Appearance
passwordLimit?: boolean
}) {
const [password, setPassword] = useState('')
const [error, setError] = useState('')
Expand All @@ -23,6 +25,11 @@ function UpdatePassword({
setError('')
setMessage('')
setLoading(true)
if (passwordLimit && password.length > 72) {
setError('Password exceeds maxmium length of 72 characters')
setLoading(false)
return
}
const { error } = await supabaseClient.auth.updateUser({ password })
if (error) setError(error.message)
else setMessage(i18n?.update_password?.confirmation_text as string)
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 @@ -106,6 +106,7 @@ export interface BaseAuth {
variables?: I18nVariables
}
theme?: 'default' | string
passwordLimit?: boolean
}

export type I18nVariables = {
Expand Down
4 changes: 4 additions & 0 deletions packages/solid/src/components/Auth/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function Auth(props: AuthProps): JSX.Element | null {
theme: 'default',
localization: { variables: {} },
otpType: 'email',
passwordLimit: false,
},
props
)
Expand Down Expand Up @@ -214,6 +215,7 @@ function Auth(props: AuthProps): JSX.Element | null {
magicLink: mergedProps().magicLink,
showLinks: mergedProps().showLinks,
i18n: i18n(),
passwordLimit: mergedProps().passwordLimit,
})

/**
Expand Down Expand Up @@ -247,6 +249,7 @@ function Auth(props: AuthProps): JSX.Element | null {
magicLink={mergedProps().magicLink}
showLinks={mergedProps().showLinks}
i18n={i18n()}
passwordLimit={mergedProps().passwordLimit}
additionalData={mergedProps().additionalData}
>
{props.children}
Expand Down Expand Up @@ -282,6 +285,7 @@ function Auth(props: AuthProps): JSX.Element | null {
<UpdatePassword
appearance={mergedProps().appearance}
supabaseClient={mergedProps().supabaseClient}
passwordLimit={mergedProps().passwordLimit}
i18n={i18n()}
/>
</Match>
Expand Down
5 changes: 5 additions & 0 deletions packages/solid/src/components/Auth/interfaces/EmailAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface EmailAuthProps {
magicLink?: boolean
i18n: I18nVariables
appearance?: Appearance
passwordLimit?: boolean
children?: JSXElement
}

Expand Down Expand Up @@ -68,6 +69,10 @@ function EmailAuth(props: EmailAuthProps) {
if (signInError) setError(signInError.message)
break
case 'sign_up':
if (props.passwordLimit && password().length > 72) {
setError('Password exceeds maxmium length of 72 characters')
return
}
let options: { emailRedirectTo: RedirectTo; data?: object } = {
emailRedirectTo: props.redirectTo,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Button, Container, Input, Label, Message } from '../../UI'
function UpdatePassword(props: {
supabaseClient: SupabaseClient
i18n: I18nVariables
passwordLimit: boolean
appearance?: Appearance
}) {
const [password, setPassword] = createSignal('')
Expand All @@ -19,6 +20,11 @@ function UpdatePassword(props: {
setError('')
setMessage('')
setLoading(true)
if (props.passwordLimit && password().length > 72) {
setError('Password exceeds maxmium length of 72 characters')
setLoading(false)
return
}
const { error } = await props.supabaseClient.auth.updateUser({
password: password(),
})
Expand Down
20 changes: 18 additions & 2 deletions packages/svelte/src/lib/Auth/Auth.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
export let theme: 'default' | string = 'default';
export let localization: { variables?: I18nVariables } = {};
export let otpType: OtpType = 'email';
export let passwordLimit: boolean = false;
export let additionalData: { [key: string]: any } | undefined = undefined;
onMount(() => {
Expand Down Expand Up @@ -108,18 +109,33 @@
{magicLink}
{showLinks}
{additionalData}
{passwordLimit}
{i18n}><slot /></EmailAuth
>
{/if}
{/if}
{#if view === VIEWS.FORGOTTEN_PASSWORD}
<ForgottenPassword {i18n} {supabaseClient} bind:authView={view} {showLinks} {appearance} {redirectTo} />
<ForgottenPassword
{i18n}
{supabaseClient}
bind:authView={view}
{showLinks}
{appearance}
{redirectTo}
/>
{/if}
{#if view === VIEWS.MAGIC_LINK}
<MagicLink {i18n} {supabaseClient} bind:authView={view} {appearance} {redirectTo} {showLinks} />
{/if}
{#if view === VIEWS.UPDATE_PASSWORD}
<UpdatePassword {i18n} {supabaseClient} bind:authView={view} {appearance} {showLinks} />
<UpdatePassword
{i18n}
{supabaseClient}
bind:authView={view}
{appearance}
{passwordLimit}
{showLinks}
/>
{/if}
{#if view === VIEWS.VERIFY_OTP}
<VerifyOtp {i18n} {supabaseClient} bind:authView={view} {appearance} {showLinks} {otpType} />
Expand Down
6 changes: 6 additions & 0 deletions packages/svelte/src/lib/Auth/interfaces/EmailAuth.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
export let showLinks = false;
export let magicLink = true;
export let i18n: I18nVariables;
export let passwordLimit: boolean = false;
export let appearance: Appearance;
let message = '';
Expand All @@ -46,6 +47,11 @@
loading = false;
break;
case VIEWS.SIGN_UP:
if (passwordLimit && password.length > 72) {
error = 'Password exceeds maxmium length of 72 characters';
loading = false;
return;
}
let options: { emailRedirectTo: RedirectTo; data?: object } = {
emailRedirectTo: redirectTo
};
Expand Down
6 changes: 6 additions & 0 deletions packages/svelte/src/lib/Auth/interfaces/UpdatePassword.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
export let supabaseClient: SupabaseClient;
export let authView: ViewType;
export let appearance: Appearance;
export let passwordLimit: boolean;
export let showLinks = false;
let password = '';
Expand All @@ -24,6 +25,11 @@
loading = true;
error = '';
message = '';
if (passwordLimit && password.length > 72) {
error = 'Password exceeds maxmium length of 72 characters';
loading = false;
return;
}
const { data, error: resetPasswordError } = await supabaseClient.auth.updateUser({
password
});
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte/src/lib/Auth/ui/SignUp.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
export let appearance: Appearance = {};
export let theme: 'default' | string = 'default';
export let localization: { variables?: I18nVariables } = {};
export let passwordLimit: boolean = false;
export let additionalData: { [key: string]: any } | undefined = undefined;
</script>

Expand All @@ -37,6 +38,7 @@
{appearance}
{theme}
{localization}
{passwordLimit}
{additionalData}
>
<slot />
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte/src/lib/Auth/ui/UpdatePassword.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export let showLinks = false;
export let appearance: Appearance = {};
export let theme: 'default' | string = 'default';
export let passwordLimit: boolean = false;
export let localization: { variables?: I18nVariables } = {};
</script>

Expand All @@ -19,5 +20,6 @@
{redirectTo}
{appearance}
{theme}
{passwordLimit}
{localization}
/>

0 comments on commit a70f74d

Please sign in to comment.