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

[Improvement] Redirect to login page if user doesn't login #3274

Merged
merged 5 commits into from
Dec 2, 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
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