fix some for iam
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import { adminRoute, fullPageAdminRoute } from './admin';
|
||||
import { branchRoute, fullPageBranchRoute } from './branch';
|
||||
import { isBranch, tokenName, userName } from '../utils';
|
||||
import { iamAppUrl, isBranch, tokenName, userName } from '../utils';
|
||||
import { useUsersStore } from '../stores/users';
|
||||
import api from '../api/client';
|
||||
|
||||
@@ -25,6 +25,12 @@ const router = createRouter({
|
||||
component: () => import('../layouts/full-page/FullPage.vue'),
|
||||
children: [
|
||||
...(isBranch() ? fullPageBranchRoute : fullPageAdminRoute),
|
||||
{
|
||||
path: '/auth/iam/callback',
|
||||
name: 'iam-callback',
|
||||
component: () => import('../views/auth/IamCallback.vue'),
|
||||
meta: { rule: 'editor' },
|
||||
},
|
||||
{
|
||||
path: '/pages/error-404',
|
||||
name: 'page-error-404',
|
||||
@@ -68,7 +74,7 @@ router.afterEach(() => {
|
||||
});
|
||||
|
||||
// legacy router.js:156-161
|
||||
const noneAuthUrl = ['/auth/login', '/auth/forgot-password', '/auth/register', '/reg'];
|
||||
const noneAuthUrl = ['/auth/login', '/auth/forgot-password', '/auth/register', '/reg', '/auth/iam/callback'];
|
||||
|
||||
/**
|
||||
* Port of legacy getPermission() (router.js:163-182).
|
||||
@@ -109,6 +115,21 @@ async function getPermission(): Promise<string[] | undefined> {
|
||||
* equivalent and produces the same user-visible result.
|
||||
*/
|
||||
router.beforeEach(async (to) => {
|
||||
if (!localStorage.getItem(tokenName) && to.path !== '/auth/iam/callback' && sessionStorage.getItem('gb_admin_iam_sso_checked') !== '1') {
|
||||
sessionStorage.setItem('gb_admin_iam_sso_checked', '1');
|
||||
try {
|
||||
const { data } = await api.get('admin/auth/sso/start', {
|
||||
params: { redirect_uri: iamAppUrl('auth/iam/callback') },
|
||||
});
|
||||
if (data?.enabled && data.authorize_url) {
|
||||
window.location.assign(data.authorize_url);
|
||||
return false;
|
||||
}
|
||||
} catch {
|
||||
// سامانه هویت برای این پنل تنظیم نشده
|
||||
}
|
||||
}
|
||||
|
||||
if (noneAuthUrl.indexOf(to.path) > -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user