Skip to content

Commit

Permalink
Redirect user to login/registration if anonymous
Browse files Browse the repository at this point in the history
Also fixes error handling.
  • Loading branch information
mvdbeek committed Oct 12, 2024
1 parent bde134f commit 59fdbfe
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 additions & 20 deletions client/src/components/Landing/WorkflowLanding.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<script setup lang="ts">
import { BAlert } from "bootstrap-vue";
import { onBeforeMount, ref } from "vue";
import { storeToRefs } from "pinia";
import { ref, watch } from "vue";
import { useRouter } from "vue-router/composables";
import { GalaxyApi } from "@/api";
import { useUserStore } from "@/stores/userStore";
import { errorMessageAsString } from "@/utils/simple-error";
import LoadingSpan from "@/components/LoadingSpan.vue";
Expand All @@ -21,34 +24,46 @@ const workflowId = ref<string | null>(null);
const errorMessage = ref<string | null>(null);
const requestState = ref<Record<string, never> | null>(null);
const instance = ref<boolean>(false);
const userStore = useUserStore();
const router = useRouter();
onBeforeMount(async () => {
const { data, error } = await GalaxyApi().GET("/api/workflow_landings/{uuid}", {
params: {
path: { uuid: props.uuid },
},
});
if (data) {
workflowId.value = data.workflow_id;
instance.value = data.workflow_target_type === "workflow";
requestState.value = data.request_state;
} else {
errorMessage.value = errorMessageAsString(error);
}
console.log(data);
});
userStore.loadUser(false);
const { isAnonymous, currentUser } = storeToRefs(userStore);
watch(
currentUser,
async () => {
if (isAnonymous.value) {
router.push(`/login/start?redirect=/workflow_landings/${props.uuid}`);
} else if (currentUser.value) {
const { data, error } = await GalaxyApi().GET("/api/workflow_landings/{uuid}", {
params: {
path: { uuid: props.uuid },
},
});
if (data) {
workflowId.value = data.workflow_id;
instance.value = data.workflow_target_type === "workflow";
requestState.value = data.request_state;
} else {
errorMessage.value = errorMessageAsString(error);
}
}
},
{ immediate: true }
);
</script>

<template>
<div>
<div v-if="!workflowId">
<LoadingSpan message="Loading workflow parameters" />
</div>
<div v-else-if="errorMessage">
<div v-if="errorMessage">
<BAlert variant="danger" show>
{{ errorMessage }}
</BAlert>
</div>
<div v-else-if="!workflowId">
<LoadingSpan message="Loading workflow parameters" />
</div>
<div v-else>
<WorkflowRun
:workflow-id="workflowId"
Expand Down

0 comments on commit 59fdbfe

Please sign in to comment.