feat: Add env variables to support exposing /workflows/demo route and /nodes.json route (#8506)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
@@ -7,8 +7,9 @@ vi.mock('@/stores/users.store', () => ({
|
||||
|
||||
describe('Checks', () => {
|
||||
describe('isAuthenticated()', () => {
|
||||
const mockUser = { id: 'user123', name: 'Test User' };
|
||||
|
||||
it('should return true if there is a current user', () => {
|
||||
const mockUser = { id: 'user123', name: 'Test User' };
|
||||
vi.mocked(useUsersStore).mockReturnValue({ currentUser: mockUser } as unknown as ReturnType<
|
||||
typeof useUsersStore
|
||||
>);
|
||||
@@ -23,5 +24,29 @@ describe('Checks', () => {
|
||||
|
||||
expect(isAuthenticated()).toBe(false);
|
||||
});
|
||||
|
||||
it('should return true if there is a current user and bypass returns false', () => {
|
||||
vi.mocked(useUsersStore).mockReturnValue({ currentUser: mockUser } as ReturnType<
|
||||
typeof useUsersStore
|
||||
>);
|
||||
|
||||
expect(isAuthenticated({ bypass: () => false })).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true if there is no current user and bypass returns true', () => {
|
||||
vi.mocked(useUsersStore).mockReturnValue({ currentUser: null } as ReturnType<
|
||||
typeof useUsersStore
|
||||
>);
|
||||
|
||||
expect(isAuthenticated({ bypass: () => true })).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false if there is no current user and bypass returns false', () => {
|
||||
vi.mocked(useUsersStore).mockReturnValue({ currentUser: null } as ReturnType<
|
||||
typeof useUsersStore
|
||||
>);
|
||||
|
||||
expect(isAuthenticated({ bypass: () => false })).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { useUsersStore } from '@/stores/users.store';
|
||||
import type { RBACPermissionCheck, AuthenticatedPermissionOptions } from '@/types/rbac';
|
||||
|
||||
export const isAuthenticated: RBACPermissionCheck<AuthenticatedPermissionOptions> = () => {
|
||||
export const isAuthenticated: RBACPermissionCheck<AuthenticatedPermissionOptions> = (options) => {
|
||||
if (options?.bypass?.()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const usersStore = useUsersStore();
|
||||
return !!usersStore.currentUser;
|
||||
};
|
||||
|
||||
@@ -7,8 +7,9 @@ export const authenticatedMiddleware: RouterMiddleware<AuthenticatedPermissionOp
|
||||
to,
|
||||
from,
|
||||
next,
|
||||
options,
|
||||
) => {
|
||||
const valid = isAuthenticated();
|
||||
const valid = isAuthenticated(options);
|
||||
if (!valid) {
|
||||
const redirect =
|
||||
to.query.redirect ??
|
||||
|
||||
Reference in New Issue
Block a user