Skip to content

Commit d4fab11

Browse files
author
Marcin Kwiatkowski
committed
refactor: fixed customer logging and authorization checking (#1081)
1 parent 59200c3 commit d4fab11

File tree

4 files changed

+6
-21
lines changed

4 files changed

+6
-21
lines changed

packages/theme/components/LoginModal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
rules="required|email"
3232
>
3333
<SfInput
34-
v-model="form.username"
34+
v-model="form.email"
3535
v-e2e="'login-modal-email'"
3636
:valid="!errors[0]"
3737
:error-message="$t(errors[0])"

packages/theme/modules/customer/composables/useUser/loginStatusPingQuery.gql.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/theme/plugins/__tests__/token-expired.spec.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const appMockFactory = (callbackResponse, authResponse) => ({
3737
},
3838
config: {
3939
state: {
40+
getCustomerToken: jest.fn(),
4041
removeCustomerToken: jest.fn(),
4142
removeCartId: jest.fn(),
4243
setMessage: jest.fn(),
@@ -65,6 +66,7 @@ describe('Token Expired plugin', () => {
6566

6667
it('sets initial login status', async () => {
6768
const appMock = appMockFactory(validRes, validRes);
69+
appMock.$vsf.$magento.config.state.getCustomerToken.mockReturnValue(true);
6870
const customerStore = useCustomerStore();
6971
jest.spyOn(customerStore, 'setIsLoggedIn');
7072

@@ -75,6 +77,7 @@ describe('Token Expired plugin', () => {
7577

7678
it('doesn\'t set initial login status if not logged in', async () => {
7779
const appMock = appMockFactory(validRes, errRes.data); // need .data because it's ApolloGraphQlResponse, not axios
80+
appMock.$vsf.$magento.config.state.getCustomerToken.mockReturnValue(false);
7881
const customerStore = useCustomerStore();
7982

8083
await tokenExpiredPlugin({ app: appMock });

packages/theme/plugins/token-expired.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ import type { Plugin } from '@nuxt/types';
22
import type { ApolloQueryResult } from '@apollo/client/core/types';
33
import type { UiNotification } from '~/composables/useUiNotification';
44
import { useCustomerStore } from '~/modules/customer/stores/customer';
5-
import loginStatusPingQueryGql from '~/modules/customer/composables/useUser/loginStatusPingQuery.gql';
65

76
export const hasGraphqlAuthorizationError = (res: ApolloQueryResult<unknown>) => res?.errors
87
?.some((error) => error.extensions.category === 'graphql-authorization') ?? false;
98

10-
const plugin : Plugin = async ({ $pinia, app }) => {
9+
const plugin : Plugin = ({ $pinia, app }) => {
1110
const customerStore = useCustomerStore($pinia);
12-
13-
const responseOfLoginStatusPing = await app.$vsf.$magento.api.customQuery({ query: loginStatusPingQueryGql });
14-
if (!hasGraphqlAuthorizationError(responseOfLoginStatusPing)) {
11+
if (app.$vsf.$magento.config.state.getCustomerToken()) {
1512
customerStore.setIsLoggedIn(true);
1613
}
1714

0 commit comments

Comments
 (0)