update
This commit is contained in:
@@ -3,7 +3,6 @@ import type { z } from 'zod'
|
||||
import { toTypedSchema } from '@vee-validate/zod'
|
||||
import { Loader2 } from 'lucide-vue-next'
|
||||
import { useForm } from 'vee-validate'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useKeycloak } from "~/composables/useKeycloack"
|
||||
|
||||
interface Props {
|
||||
@@ -37,7 +36,7 @@ const onSubmit = handleSubmit(async (values) => {
|
||||
}
|
||||
})
|
||||
|
||||
const { initKeycloak, getProfile, login } = useKeycloak()
|
||||
const { initKeycloak, getProfile, loginSSO } = useKeycloak()
|
||||
const profile = ref<any>(null)
|
||||
|
||||
onMounted(async () => {
|
||||
@@ -49,7 +48,7 @@ onMounted(async () => {
|
||||
const onSSO = (async () => {
|
||||
try {
|
||||
const redirect = window.location.origin + '/auth/sso'
|
||||
await login({ redirectUri: redirect })
|
||||
await loginSSO({ redirectUri: redirect })
|
||||
} catch (error) {
|
||||
console.error('Call SSO failed:', error)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { useSidebar } from '~/components/pub/ui/sidebar'
|
||||
import { useKeycloak } from "~/composables/useKeycloack"
|
||||
|
||||
// defineProps<{
|
||||
// user: {
|
||||
@@ -11,11 +12,15 @@ import { useSidebar } from '~/components/pub/ui/sidebar'
|
||||
|
||||
const { isMobile } = useSidebar()
|
||||
const { user, logout, setActiveRole, getActiveRole } = useUserStore()
|
||||
const { initKeycloak, logoutSSO } = useKeycloak()
|
||||
// const userStore = useUserStore().user
|
||||
|
||||
function handleLogout() {
|
||||
initKeycloak('check-sso')
|
||||
|
||||
navigateTo('/auth/login')
|
||||
logout()
|
||||
logoutSSO(window.location.origin + '/auth/login')
|
||||
}
|
||||
|
||||
const showModalTheme = ref(false)
|
||||
|
||||
@@ -57,12 +57,12 @@ export function useKeycloak() {
|
||||
}
|
||||
};
|
||||
|
||||
const login = (options?: Keycloak.KeycloakLoginOptions) => {
|
||||
const loginSSO = (options?: Keycloak.KeycloakLoginOptions) => {
|
||||
if (!kc) throw new Error("Keycloak not initialized");
|
||||
return kc.login(options);
|
||||
};
|
||||
|
||||
const logout = (redirectUri?: string) => {
|
||||
const logoutSSO = (redirectUri?: string) => {
|
||||
if (!kc) throw new Error("Keycloak not initialized");
|
||||
return kc.logout({ redirectUri });
|
||||
};
|
||||
@@ -78,6 +78,7 @@ export function useKeycloak() {
|
||||
// });
|
||||
|
||||
const apiErrors = ref<Record<string, string>>({})
|
||||
const { login } = useUserStore()
|
||||
|
||||
const getResponse = async () => {
|
||||
console.log("=================== onto login fes!!! ===================")
|
||||
@@ -108,8 +109,8 @@ export function useKeycloak() {
|
||||
|
||||
return {
|
||||
initKeycloak,
|
||||
login,
|
||||
logout,
|
||||
loginSSO,
|
||||
logoutSSO,
|
||||
getToken,
|
||||
isAuthenticated,
|
||||
getProfile,
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useKeycloak } from "~/composables/useKeycloack"
|
||||
|
||||
export default defineNuxtRouteMiddleware(async (to) => {
|
||||
if (to.meta.public) return
|
||||
// if (!to.meta?.requiresAuth) return;
|
||||
|
||||
const { $pinia } = useNuxtApp()
|
||||
|
||||
@@ -11,8 +12,9 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
||||
if (import.meta.client) {
|
||||
const userStore = useUserStore($pinia)
|
||||
if (!userStore.isAuthenticated && !isAuthenticated.value) {
|
||||
// await login({ redirectUri: window.location.origin + to.fullPath });
|
||||
return navigateTo('/auth/login')
|
||||
} else {
|
||||
console.log("its logged in!!! ")
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user