forget password send link, localized

This commit is contained in:
tonyrewin 2022-11-02 01:25:18 +03:00
parent a63cde416f
commit 1c38fc124b
5 changed files with 19 additions and 10 deletions

View File

@ -7,7 +7,8 @@ import { useRouter } from '../../../stores/router'
import { email, setEmail } from './sharedLogic'
import type { AuthModalSearchParams } from './types'
import { isValidEmail } from './validators'
import { ApiError } from '../../../utils/apiClient'
import { signSendLink } from '../../../stores/auth'
import { locale } from '../../../stores/ui'
type FormFields = {
email: string
@ -51,7 +52,8 @@ export const ForgotPasswordForm = () => {
setIsSubmitting(true)
try {
// TODO: send mail with link to new password form
setSubmitError('')
signSendLink({ email: email(), lang: locale() })
} catch (error) {
setSubmitError(error.message)
} finally {

View File

@ -10,6 +10,7 @@ import { isValidEmail } from './validators'
import { email, setEmail } from './sharedLogic'
import { useRouter } from '../../../stores/router'
import type { AuthModalSearchParams } from './types'
import { hideModal, locale } from '../../../stores/ui'
type FormFields = {
email: string
@ -37,6 +38,14 @@ export const LoginForm = () => {
setPassword(newPassword)
}
const handleSendLinkAgainClick = (event: Event) => {
event.preventDefault()
setIsEmailNotConfirmed(false)
setSubmitError('')
setIsLinkSent(true)
signSendLink({ email: email(), lang: locale() })
}
const handleSubmit = async (event: Event) => {
event.preventDefault()

View File

@ -1,8 +1,8 @@
import { gql } from '@urql/core'
export default gql`
query SendLinkQuery($email: String!) {
sendLink(email: $email) {
mutation SendLinkQuery($email: String!, $lang: String) {
sendLink(email: $email, lang: $lang) {
error
}
}

View File

@ -54,9 +54,8 @@ export const register = async ({
})
}
export const signSendLink = async (params) => {
await apiClient.authSendLink(params) // { email }
resetToken()
export const signSendLink = async ({ email, lang }: { email: string, lang: string }) => {
await apiClient.authSendLink({ email, lang })
}
export const renewSession = async () => {

View File

@ -93,12 +93,11 @@ export const apiClient = {
authCheckEmail: async ({ email }) => {
// check if email is used
const response = await publicGraphQLClient.query(authCheckEmailQuery, { email }).toPromise()
console.debug('[api-client] authCheckEmail', response)
return response.data.isEmailUsed
},
authSendLink: async ({ email }) => {
authSendLink: async ({ email, lang }) => {
// send link with code on email
const response = await publicGraphQLClient.query(authSendLinkMutation, { email }).toPromise()
const response = await publicGraphQLClient.mutation(authSendLinkMutation, { email, lang }).toPromise()
return response.data.reset
},
confirmEmail: async ({ token }: { token: string }) => {