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