Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved: login flow, remove user-profile support fetching logic and remove permission check logic(#14) #16

Merged
merged 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,55 +11,29 @@
/**
* 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 / reusable_workflow_job (20.x)

Unexpected console statement
return Promise.reject(new Error(resp.data._ERROR_MESSAGE_));
}
} else {
showToast(translate("Something went wrong"));
console.error("error", resp.data._ERROR_MESSAGE_);

Check warning on line 31 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 31 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
return Promise.reject(new Error(resp.data._ERROR_MESSAGE_));
}
} catch (err: any) {
showToast(translate("Something went wrong"));
console.error("error", err);

Check warning on line 36 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 36 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
return Promise.reject(new Error(err))
}
// return resp
Expand All @@ -74,16 +48,6 @@

},

/**
* 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 @@
/**
* 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
Loading