authorizer-upgrade-3
This commit is contained in:
parent
cf19cdd39b
commit
5a95e7490e
|
@ -12,7 +12,6 @@ import { validateEmail } from '../../../utils/validateEmail'
|
||||||
import { email, setEmail } from './sharedLogic'
|
import { email, setEmail } from './sharedLogic'
|
||||||
|
|
||||||
import styles from './AuthModal.module.scss'
|
import styles from './AuthModal.module.scss'
|
||||||
import { ApiResponse, ForgotPasswordResponse } from '@authorizerdev/authorizer-js'
|
|
||||||
|
|
||||||
type FormFields = {
|
type FormFields = {
|
||||||
email: string
|
email: string
|
||||||
|
@ -28,7 +27,7 @@ export const ForgotPasswordForm = () => {
|
||||||
setEmail(newEmail.toLowerCase())
|
setEmail(newEmail.toLowerCase())
|
||||||
}
|
}
|
||||||
const {
|
const {
|
||||||
actions: { authorizer },
|
actions: { forgotPassword },
|
||||||
} = useSession()
|
} = useSession()
|
||||||
const [submitError, setSubmitError] = createSignal('')
|
const [submitError, setSubmitError] = createSignal('')
|
||||||
const [isSubmitting, setIsSubmitting] = createSignal(false)
|
const [isSubmitting, setIsSubmitting] = createSignal(false)
|
||||||
|
@ -62,22 +61,28 @@ export const ForgotPasswordForm = () => {
|
||||||
|
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
try {
|
try {
|
||||||
const response: ApiResponse<ForgotPasswordResponse> = await authorizer().forgotPassword({
|
const { data, errors } = await forgotPassword({
|
||||||
email: email(),
|
email: email(),
|
||||||
redirect_uri: window.location.origin,
|
redirect_uri: window.location.origin,
|
||||||
})
|
})
|
||||||
console.debug('[ForgotPasswordForm] authorizer response:', response)
|
if (data) {
|
||||||
if (response?.data) setMessage(response.data.message)
|
console.debug('[ForgotPasswordForm] authorizer response:', data)
|
||||||
else {
|
setMessage(data.message)
|
||||||
console.warn(response.errors)
|
}
|
||||||
|
if (errors) {
|
||||||
|
console.warn(errors)
|
||||||
|
if (errors) {
|
||||||
|
const error: Error = errors[0]
|
||||||
|
if (error.cause === 'user_not_found') {
|
||||||
|
setIsUserNotFound(true)
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
setSubmitError(error.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
if (error?.code === 'user_not_found') {
|
|
||||||
setIsUserNotFound(true)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
setSubmitError(error?.message)
|
|
||||||
} finally {
|
} finally {
|
||||||
setIsSubmitting(false)
|
setIsSubmitting(false)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,8 @@ import {
|
||||||
AuthorizeResponse,
|
AuthorizeResponse,
|
||||||
ApiResponse,
|
ApiResponse,
|
||||||
GenericResponse,
|
GenericResponse,
|
||||||
// GraphqlQueryInput,
|
ForgotPasswordResponse,
|
||||||
|
ForgotPasswordInput,
|
||||||
} from '@authorizerdev/authorizer-js'
|
} from '@authorizerdev/authorizer-js'
|
||||||
import {
|
import {
|
||||||
createContext,
|
createContext,
|
||||||
|
@ -62,6 +63,9 @@ export type SessionContextType = {
|
||||||
signIn: (params: LoginInput) => Promise<void>
|
signIn: (params: LoginInput) => Promise<void>
|
||||||
signOut: () => Promise<void>
|
signOut: () => Promise<void>
|
||||||
oauth: (provider: string) => Promise<void>
|
oauth: (provider: string) => Promise<void>
|
||||||
|
forgotPassword: (
|
||||||
|
params: ForgotPasswordInput,
|
||||||
|
) => Promise<{ data: ForgotPasswordResponse; errors: Error[] }>
|
||||||
changePassword: (password: string, token: string) => void
|
changePassword: (password: string, token: string) => void
|
||||||
confirmEmail: (input: VerifyEmailInput) => Promise<AuthToken | void> // email confirm callback is in auth.discours.io
|
confirmEmail: (input: VerifyEmailInput) => Promise<AuthToken | void> // email confirm callback is in auth.discours.io
|
||||||
setIsSessionLoaded: (loaded: boolean) => void
|
setIsSessionLoaded: (loaded: boolean) => void
|
||||||
|
@ -293,6 +297,12 @@ export const SessionProvider = (props: {
|
||||||
console.debug('[context.session] change password response:', resp)
|
console.debug('[context.session] change password response:', resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const forgotPassword = async (params: ForgotPasswordInput) => {
|
||||||
|
const resp = await authorizer().forgotPassword(params)
|
||||||
|
console.debug('[context.session] change password response:', resp)
|
||||||
|
return { data: resp?.data, errors: resp.errors }
|
||||||
|
}
|
||||||
|
|
||||||
const confirmEmail = async (input: VerifyEmailInput) => {
|
const confirmEmail = async (input: VerifyEmailInput) => {
|
||||||
console.debug(`[context.session] calling authorizer's verify email with`, input)
|
console.debug(`[context.session] calling authorizer's verify email with`, input)
|
||||||
try {
|
try {
|
||||||
|
@ -338,6 +348,7 @@ export const SessionProvider = (props: {
|
||||||
setAuthor,
|
setAuthor,
|
||||||
authorizer,
|
authorizer,
|
||||||
loadAuthor,
|
loadAuthor,
|
||||||
|
forgotPassword,
|
||||||
changePassword,
|
changePassword,
|
||||||
oauth,
|
oauth,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user