Skip to content

Commit

Permalink
24.04.13: userinfo module refactor [WTEL-4374]
Browse files Browse the repository at this point in the history
  • Loading branch information
dlohvinov committed Mar 21, 2024
1 parent ffa79c0 commit 19bb35e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 187 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webitel/ui-sdk",
"version": "24.4.12",
"version": "24.4.13",
"private": false,
"scripts": {
"dev": "vite",
Expand Down
7 changes: 0 additions & 7 deletions src/modules/Userinfo/api/BaseAPIService.js

This file was deleted.

31 changes: 0 additions & 31 deletions src/modules/Userinfo/api/auth.js

This file was deleted.

30 changes: 17 additions & 13 deletions src/modules/Userinfo/api/userinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ import applyTransform, {
notify,
snakeToCamel,
} from '../../../api/transformers';
import BaseAPIService from './BaseAPIService';

class UserinfoAPI extends BaseAPIService {
// gets user by token from localstorage
// stores response username in vuex
const userinfo = (instance) => ({
async getSession() {
// const tokenCheck = localStorage.getItem('access-token');
// if (typeof tokenCheck === 'string') { // if there is no token, localStorage returns object
const url = '/userinfo';
try {
const response = await this._instance.get(url);
const response = await instance.get(url);
return applyTransform(response.data, [
snakeToCamel(),
]);
Expand All @@ -21,13 +16,12 @@ class UserinfoAPI extends BaseAPIService {
notify,
]);
}
// }
}
},

async getApplicationsAccess() {
const url = 'role/metadata/access';
try {
const response = await this._instance.get(url);
const response = await instance.get(url);
return applyTransform(response.data, [
snakeToCamel(),
]);
Expand All @@ -36,9 +30,19 @@ class UserinfoAPI extends BaseAPIService {
notify,
]);
}
}
}
},

async logout() {
const url = '/logout';

const userinfo = new UserinfoAPI();
try {
return await instance.post(url, {});
} catch (err) {
throw applyTransform(err, [
notify,
]);
}
}
});

export default userinfo;
54 changes: 0 additions & 54 deletions src/modules/Userinfo/components/__tests__/auth.spec.js

This file was deleted.

79 changes: 0 additions & 79 deletions src/modules/Userinfo/components/the-auth.vue

This file was deleted.

14 changes: 12 additions & 2 deletions src/modules/Userinfo/store/UserinfoStoreModule.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import userinfo from '../api/userinfo';
import userinfoGenerator from '../api/userinfo';

Check failure on line 1 in src/modules/Userinfo/store/UserinfoStoreModule.js

View workflow job for this annotation

GitHub Actions / Qodana for JS

ESLint

ESLint: Install the 'eslint' package
import ApplicationsAccess from '../classes/ApplicationsAccess';
import BaseStoreModule from '../../../store/BaseStoreModules/BaseStoreModule';
import Permissions from '../enums/Permissions.enum';

let userinfo = null;

const defaultState = () => ({
isLoading: true,
domainId: 0,
Expand Down Expand Up @@ -87,7 +89,9 @@ export default class UserinfoStoreModule extends BaseStoreModule {
return permissions;
},

OPEN_SESSION: async (context) => {
OPEN_SESSION: async (context, { instance }) => {
let userinfo = userinfoGenerator(instance);

await context.dispatch('BEFORE_OPEN_SESSION_HOOK');
// !!! it should be checked in router.js beforeEach hook
// if (!localStorage.getItem('access-token')) {
Expand Down Expand Up @@ -122,6 +126,12 @@ export default class UserinfoStoreModule extends BaseStoreModule {
}
},

LOGOUT: async (context, { authUrl = import.meta.env.VITE_AUTH_URL }) => {
if (!authUrl) throw new Error('No authUrl for LOGOUT provided');
await userinfo.logout();
window.location.href = authUrl;
},

SET_APPLICATIONS_ACCESS: (context, access) => context.commit('SET_APPLICATIONS_ACCESS', access),

SET_LOADING: (context, isLoading) => {
Expand Down

0 comments on commit 19bb35e

Please sign in to comment.