@@ -8,8 +8,8 @@ import { client } from './client';
8
8
import { graphql } from './client/graphql' ;
9
9
10
10
const LoginMutation = graphql ( `
11
- mutation Login($email: String!, $password: String!) {
12
- login(email: $email, password: $password) {
11
+ mutation Login($email: String!, $password: String!, $cartEntityId: String ) {
12
+ login(email: $email, password: $password, guestCartEntityId: $cartEntityId ) {
13
13
customerAccessToken {
14
14
value
15
15
}
@@ -23,18 +23,6 @@ const LoginMutation = graphql(`
23
23
}
24
24
` ) ;
25
25
26
- const AssignCartToCustomerMutation = graphql ( `
27
- mutation AssignCartToCustomer($assignCartToCustomerInput: AssignCartToCustomerInput!) {
28
- cart {
29
- assignCartToCustomer(input: $assignCartToCustomerInput) {
30
- cart {
31
- entityId
32
- }
33
- }
34
- }
35
- }
36
- ` ) ;
37
-
38
26
const LogoutMutation = graphql ( `
39
27
mutation LogoutMutation {
40
28
logout {
@@ -74,30 +62,6 @@ const config = {
74
62
} ,
75
63
} ,
76
64
events : {
77
- async signIn ( { user : { customerAccessToken } } ) {
78
- const cookieStore = await cookies ( ) ;
79
- const cookieCartId = cookieStore . get ( 'cartId' ) ?. value ;
80
-
81
- if ( cookieCartId ) {
82
- try {
83
- await client . fetch ( {
84
- document : AssignCartToCustomerMutation ,
85
- variables : {
86
- assignCartToCustomerInput : {
87
- cartEntityId : cookieCartId ,
88
- } ,
89
- } ,
90
- customerAccessToken,
91
- fetchOptions : {
92
- cache : 'no-store' ,
93
- } ,
94
- } ) ;
95
- } catch ( error ) {
96
- // eslint-disable-next-line no-console
97
- console . error ( error ) ;
98
- }
99
- }
100
- } ,
101
65
async signOut ( message ) {
102
66
const customerAccessToken = 'token' in message ? message . token ?. customerAccessToken : null ;
103
67
@@ -126,10 +90,12 @@ const config = {
126
90
} ,
127
91
async authorize ( credentials ) {
128
92
const { email, password } = Credentials . parse ( credentials ) ;
93
+ const cookieStore = await cookies ( ) ;
94
+ const cartEntityId = cookieStore . get ( 'cartId' ) ?. value ;
129
95
130
96
const response = await client . fetch ( {
131
97
document : LoginMutation ,
132
- variables : { email, password } ,
98
+ variables : { email, password, cartEntityId } ,
133
99
fetchOptions : {
134
100
cache : 'no-store' ,
135
101
} ,
0 commit comments