Skip to content

Commit

Permalink
[Improvement] Redirect to login page if user doesn't login (#3274)
Browse files Browse the repository at this point in the history
Co-authored-by: ZhouJinsong <[email protected]>
Co-authored-by: baiyangtx <[email protected]>
Co-authored-by: ConradJam <[email protected]>
  • Loading branch information
4 people authored Dec 2, 2024
1 parent 604d1c1 commit b6b1e0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions amoro-web/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,17 @@ RegisterComponents(app);
finally {
const store = useStore()
router.beforeEach((to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext) => {
if (to.fullPath === '/login') {
if (store.userInfo.userName) {
return next('/')
}
// if no username in store and not go to login page, should redirect to login page
if (!store.userInfo.userName && to.path !== '/login') {
store.setHistoryPath({
path: from.path,
query: { ...from.query },
query: from.query,
})
next('/login')
}
else {
next()
}
next()
})

app.use(router)
Expand Down
4 changes: 2 additions & 2 deletions amoro-web/src/views/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License.

<script lang="ts">
import { message } from 'ant-design-vue'
import { computed, defineComponent, onMounted, reactive } from 'vue'
import { computed, defineComponent, reactive } from 'vue'
import { useRouter } from 'vue-router'
import loginService from '@/services/login.service'
import { usePlaceholder } from '@/hooks/usePlaceholder'
Expand Down Expand Up @@ -63,7 +63,7 @@ export default defineComponent({
const disabled = computed(() => {
return !(formState.username && formState.password)
})
onMounted(() => {})

return {
placeholder,
formState,
Expand Down

0 comments on commit b6b1e0f

Please sign in to comment.