2020-07-07 10:14:12 +00:00
|
|
|
import { fragmentUser } from "@saleor/fragments/auth";
|
|
|
|
import { accountErrorFragment } from "@saleor/fragments/errors";
|
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
|
|
|
|
errors {
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
user {
|
|
|
|
...User
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export const TypedTokenAuthMutation = TypedMutation<
|
|
|
|
TokenAuth,
|
|
|
|
TokenAuthVariables
|
|
|
|
>(tokenAuthMutation);
|
|
|
|
|
|
|
|
export const tokenVerifyMutation = gql`
|
|
|
|
${fragmentUser}
|
|
|
|
mutation VerifyToken($token: String!) {
|
|
|
|
tokenVerify(token: $token) {
|
|
|
|
payload
|
|
|
|
user {
|
|
|
|
...User
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export const TypedVerifyTokenMutation = TypedMutation<
|
|
|
|
VerifyToken,
|
|
|
|
VerifyTokenVariables
|
|
|
|
>(tokenVerifyMutation);
|
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);
|
2020-05-07 11:04:15 +00:00
|
|
|
|
|
|
|
const refreshToken = gql`
|
|
|
|
mutation RefreshToken($token: String!) {
|
2020-07-01 11:11:08 +00:00
|
|
|
tokenRefresh(csrfToken: $token) {
|
2020-05-07 11:04:15 +00:00
|
|
|
token
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const TokenRefreshMutation = TypedMutation<
|
|
|
|
RefreshToken,
|
|
|
|
RefreshTokenVariables
|
|
|
|
>(refreshToken);
|