fix(auth): relax keycloak audience check and auto-redirect logged-in user
This commit is contained in:
@@ -35,11 +35,14 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { getOidcAuthorizeUrl } from '@/api/auth'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const authStore = useAuthStore()
|
||||
|
||||
const loginLoading = ref(false)
|
||||
const error = ref('')
|
||||
@@ -49,6 +52,16 @@ function getPostLoginRedirect() {
|
||||
return typeof redirect === 'string' ? redirect : '/me'
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (!authStore.isLoggedIn) return
|
||||
try {
|
||||
await authStore.fetchMe()
|
||||
router.replace(getPostLoginRedirect())
|
||||
} catch (_err) {
|
||||
authStore.logout()
|
||||
}
|
||||
})
|
||||
|
||||
async function handleLogin() {
|
||||
loginLoading.value = true
|
||||
error.value = ''
|
||||
|
||||
Reference in New Issue
Block a user