| Conditions | 3 |
| Total Lines | 28 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | /** |
||
| 6 | |||
| 7 | // eslint-disable-next-line sw-deprecation-rules/private-feature-declarations |
||
| 8 | export default function initializeUserContext() { |
||
| 9 | return new Promise<void>((resolve) => { |
||
| 10 | const loginService = Shopware.Service('loginService'); |
||
| 11 | const userService = Shopware.Service('userService'); |
||
| 12 | |||
| 13 | // The user isn't logged in |
||
| 14 | if (!loginService.isLoggedIn()) { |
||
| 15 | // Remove existing login info from the locale storage |
||
| 16 | loginService.logout(); |
||
| 17 | resolve(); |
||
| 18 | return; |
||
| 19 | } |
||
| 20 | |||
| 21 | userService.getUser().then((response) => { |
||
| 22 | // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment |
||
| 23 | const data = response?.data; |
||
| 24 | // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access |
||
| 25 | delete data.password; |
||
| 26 | |||
| 27 | Shopware.State.commit('setCurrentUser', data); |
||
| 28 | initializeUserNotifications(); |
||
| 29 | resolve(); |
||
| 30 | }).catch(() => { |
||
| 31 | // An error occurred which means the user isn't logged in so get rid of the information in local storage |
||
| 32 | loginService.logout(); |
||
| 33 | resolve(); |
||
| 34 | }); |
||
| 37 |