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

View File

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

View File

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

View File

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

View File

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