Skip to content

Commit

Permalink
Merge pull request #16 from ymaheshwari1/#14
Browse files Browse the repository at this point in the history
Improved: login flow, remove user-profile support fetching logic and remove permission check logic(#14)
  • Loading branch information
ymaheshwari1 authored Jan 12, 2024
2 parents d4e0a68 + ef3a5e3 commit 1efa5e3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 62 deletions.
3 changes: 2 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ axios.interceptors.request.use((config: any) => {
return config;
});

// TODO: need to update this as per the changes in the Moqui response format, if required.
axios.interceptors.response.use(function (response) {
// Any status code that lie within the range of 2xx cause this function to trigger
// Do something with response data
Expand Down Expand Up @@ -69,7 +70,7 @@ const api = async (customConfig: any) => {
}

const baseURL = store.getters["user/getInstanceUrl"];
if (baseURL) config.baseURL = `https://${baseURL}.hotwax.io/api/`;
if (baseURL) config.baseURL = `https://${baseURL}.hotwax.io/rest/s1/order-routing/`;
if(customConfig.cache) config.adapter = axiosCache.adapter;
const networkStatus = await OfflineHelper.getNetworkStatus();
if (customConfig.queue && !networkStatus.connected) {
Expand Down
11 changes: 2 additions & 9 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@ const login = async (username: string, password: string): Promise <any> => {
url: "login",
method: "post",
data: {
"USERNAME": username,
"PASSWORD": password
username,
password
}
});
}

const getProfile = async (): Promise <any> => {
return api({
url: "user-profile",
method: "get",
});
}
const getAvailableTimeZones = async (): Promise <any> => {
return api({
url: "getAvailableTimeZones",
Expand Down Expand Up @@ -47,7 +41,6 @@ const checkPermission = async (payload: any): Promise <any> => {
export const UserService = {
login,
getAvailableTimeZones,
getProfile,
setUserTimeZone,
checkPermission
}
50 changes: 7 additions & 43 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,16 @@ const actions: ActionTree<UserState, RootState> = {
/**
* Login user and return token
*/
async login ({ commit, dispatch }, { username, password }) {
async login({ commit }, { username, password }) {
try {
// TODO: implement support for fetching user-profile
// TODO: implement support for permission check
// TODO: implement support for fetching product stores for user
const resp = await UserService.login(username, password)
if (resp.status === 200 && resp.data) {
if (resp.data.token) {
const permissionId = process.env.VUE_APP_PERMISSION_ID;
if (permissionId) {
const checkPermissionResponse = await UserService.checkPermission({
data: {
permissionId
},
headers: {
Authorization: "Bearer " + resp.data.token,
"Content-Type": "application/json"
}
});

if (checkPermissionResponse.status === 200 && !hasError(checkPermissionResponse) && checkPermissionResponse.data && checkPermissionResponse.data.hasPermission) {
commit(types.USER_TOKEN_CHANGED, { newToken: resp.data.token })
dispatch("getProfile")
if (resp.data._EVENT_MESSAGE_ && resp.data._EVENT_MESSAGE_.startsWith("Alert:")) {
// TODO Internationalise text
showToast(translate(resp.data._EVENT_MESSAGE_));
}
return resp.data;
} else {
const permissionError = "You do not have permission to access the app.";
showToast(translate(permissionError));
console.error("error", permissionError);
return Promise.reject(new Error(permissionError));
}
} else {
commit(types.USER_TOKEN_CHANGED, { newToken: resp.data.token })
dispatch("getProfile")
return resp.data;
}
commit(types.USER_TOKEN_CHANGED, { newToken: resp.data.token })
return resp.data;
} else if (hasError(resp)) {
showToast(translate("Sorry, your username or password is incorrect. Please try again."));
console.error("error", resp.data._ERROR_MESSAGE_);

Check warning on line 26 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

Unexpected console statement

Check warning on line 26 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / build_and_deploy

Unexpected console statement

Check warning on line 26 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

Unexpected console statement
Expand Down Expand Up @@ -74,16 +48,6 @@ const actions: ActionTree<UserState, RootState> = {

},

/**
* Get User profile
*/
async getProfile ( { commit }) {
const resp = await UserService.getProfile()
if (resp.status === 200) {
commit(types.USER_INFO_UPDATED, resp.data);
}
},

/**
* update current facility information
*/
Expand All @@ -107,7 +71,7 @@ const actions: ActionTree<UserState, RootState> = {
/**
* Set User Instance Url
*/
setUserInstanceUrl ({ state, commit }, payload){
setUserInstanceUrl ({ commit }, payload){
commit(types.USER_INSTANCE_URL_UPDATED, payload)
}
}
Expand Down
14 changes: 5 additions & 9 deletions src/views/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
<Logo />

<ion-item lines="full">
<ion-label position="fixed">{{ $t("OMS") }}</ion-label>
<ion-input name="instanceUrl" v-model="instanceUrl" id="instanceUrl" type="text" required />
<ion-input label-placement="fixed" :label="$t('OMS')" name="instanceUrl" v-model="instanceUrl" id="instanceUrl" type="text" required />
</ion-item>
<ion-item lines="full">
<ion-label position="fixed">{{ $t("Username") }}</ion-label>
<ion-input name="username" v-model="username" id="username" type="text" required />
<ion-input label-placement="fixed" :label="$t('Username')" name="username" v-model="username" id="username" type="text" required />
</ion-item>
<ion-item lines="none">
<ion-label position="fixed">{{ $t("Password") }}</ion-label>
<ion-input name="password" v-model="password" id="password" type="password" required />
<ion-input label-placement="fixed" :label="$t('Password')" name="password" v-model="password" id="password" type="password" required />
</ion-item>

<div class="ion-padding">
Expand All @@ -33,8 +30,8 @@ import {
IonContent,
IonInput,
IonItem,
IonLabel,
IonPage } from "@ionic/vue";
IonPage
} from "@ionic/vue";
import { defineComponent } from "vue";
import { useRouter } from "vue-router";
import { useStore } from "@/store";
Expand All @@ -48,7 +45,6 @@ export default defineComponent({
IonContent,
IonInput,
IonItem,
IonLabel,
IonPage,
Logo
},
Expand Down

0 comments on commit 1efa5e3

Please sign in to comment.