2020-07-07 10:14:12 +00:00
|
|
|
import { fragmentUser } from "@saleor/fragments/auth";
|
|
|
|
import { accountErrorFragment } from "@saleor/fragments/errors";
|
2020-07-13 14:53:48 +00:00
|
|
|
import makeMutation from "@saleor/hooks/makeMutation";
|
2019-06-19 14:40:52 +00:00
|
|
|
import gql from "graphql-tag";
|
|
|
|
|
|
|
|
import { TypedMutation } from "../mutations";
|
2020-05-14 09:30:32 +00:00
|
|
|
import { RefreshToken, RefreshTokenVariables } from "./types/RefreshToken";
|
2019-09-02 19:23:37 +00:00
|
|
|
import {
|
|
|
|
RequestPasswordReset,
|
|
|
|
RequestPasswordResetVariables
|
|
|
|
} from "./types/RequestPasswordReset";
|
2019-09-03 13:42:15 +00:00
|
|
|
import { SetPassword, SetPasswordVariables } from "./types/SetPassword";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { TokenAuth, TokenAuthVariables } from "./types/TokenAuth";
|
|
|
|
import { VerifyToken, VerifyTokenVariables } from "./types/VerifyToken";
|
|
|
|
|
|
|
|
export const tokenAuthMutation = gql`
|
|
|
|
${fragmentUser}
|
|
|
|
mutation TokenAuth($email: String!, $password: String!) {
|
|
|
|
tokenCreate(email: $email, password: $password) {
|
|
|
|
token
|
2020-07-13 14:53:48 +00:00
|
|
|
errors: accountErrors {
|
2019-06-19 14:40:52 +00:00
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
user {
|
|
|
|
...User
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2020-07-13 14:53:48 +00:00
|
|
|
export const useTokenAuthMutation = makeMutation<TokenAuth, TokenAuthVariables>(
|
|
|
|
tokenAuthMutation
|
|
|
|
);
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
export const tokenVerifyMutation = gql`
|
|
|
|
${fragmentUser}
|
|
|
|
mutation VerifyToken($token: String!) {
|
|
|
|
tokenVerify(token: $token) {
|
|
|
|
payload
|
|
|
|
user {
|
|
|
|
...User
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2020-07-13 14:53:48 +00:00
|
|
|
export const useTokenVerifyMutation = makeMutation<
|
2019-06-19 14:40:52 +00:00
|
|
|
VerifyToken,
|
|
|
|
VerifyTokenVariables
|
|
|
|
>(tokenVerifyMutation);
|
2019-09-02 19:23:37 +00:00
|
|
|
|
2020-07-13 14:53:48 +00:00
|
|
|
const refreshToken = gql`
|
|
|
|
mutation RefreshToken($token: String!) {
|
|
|
|
tokenRefresh(csrfToken: $token) {
|
|
|
|
token
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const useTokenRefreshMutation = makeMutation<
|
|
|
|
RefreshToken,
|
|
|
|
RefreshTokenVariables
|
|
|
|
>(refreshToken);
|
|
|
|
|
2019-09-02 19:23:37 +00:00
|
|
|
export const requestPasswordReset = gql`
|
2020-04-23 15:43:08 +00:00
|
|
|
${accountErrorFragment}
|
2019-09-02 19:23:37 +00:00
|
|
|
mutation RequestPasswordReset($email: String!, $redirectUrl: String!) {
|
|
|
|
requestPasswordReset(email: $email, redirectUrl: $redirectUrl) {
|
2020-03-10 13:33:43 +00:00
|
|
|
errors: accountErrors {
|
|
|
|
...AccountErrorFragment
|
2019-09-02 19:23:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const RequestPasswordResetMutation = TypedMutation<
|
|
|
|
RequestPasswordReset,
|
|
|
|
RequestPasswordResetVariables
|
|
|
|
>(requestPasswordReset);
|
2019-09-03 13:42:15 +00:00
|
|
|
|
|
|
|
export const setPassword = gql`
|
2020-04-23 15:43:08 +00:00
|
|
|
${accountErrorFragment}
|
2019-09-03 13:42:15 +00:00
|
|
|
${fragmentUser}
|
|
|
|
mutation SetPassword($email: String!, $password: String!, $token: String!) {
|
|
|
|
setPassword(email: $email, password: $password, token: $token) {
|
2020-03-10 13:33:43 +00:00
|
|
|
errors: accountErrors {
|
|
|
|
...AccountErrorFragment
|
2019-09-03 13:42:15 +00:00
|
|
|
}
|
2020-03-10 13:33:43 +00:00
|
|
|
token
|
2019-09-03 13:42:15 +00:00
|
|
|
user {
|
|
|
|
...User
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const SetPasswordMutation = TypedMutation<
|
|
|
|
SetPassword,
|
|
|
|
SetPasswordVariables
|
|
|
|
>(setPassword);
|