fix redirects

This commit is contained in:
Damodar Lohani
2024-09-18 15:15:23 +05:45
parent 4e08ae5e4f
commit a5532d84ba
3 changed files with 8 additions and 7 deletions
-1
View File
@@ -41,7 +41,6 @@ export const canWriteTopics = derived(scopes, ($scopes) => $scopes.includes('top
export const canSeeBilling = derived(scopes, ($scopes) => $scopes.includes('billing.read'));
export const canSeeProjects = derived(scopes, function ($scopes) {
console.log($scopes);
return $scopes.includes('projects.read');
});
export const canSeeDatabases = derived(scopes, ($scopes) => $scopes.includes('databases.read'));
@@ -4,17 +4,14 @@ import { getLimit, getPage, pageToOffset } from '$lib/helpers/load';
import { CARD_LIMIT, Dependencies } from '$lib/constants';
import type { PageLoad } from './$types';
import { redirect } from '@sveltejs/kit';
import { canSeeProjects } from '$lib/stores/roles';
import { get } from 'svelte/store';
export const load: PageLoad = async ({ params, url, route, depends, parent }) => {
await parent();
const {roles, scopes} = await parent();
depends(Dependencies.ORGANIZATION);
const page = getPage(url);
const limit = getLimit(url, route, CARD_LIMIT);
const offset = pageToOffset(page, limit);
if (!get(canSeeProjects)) {
if (!scopes.includes('projects.read') && scopes.includes('billing.read')) {
return redirect(301, `/console/organization-${params.organization}/billing`);
}
@@ -2,10 +2,15 @@ import { Dependencies } from '$lib/constants';
import type { Address } from '$lib/sdk/billing';
import type { Organization } from '$lib/stores/organization';
import { sdk } from '$lib/stores/sdk';
import { redirect } from '@sveltejs/kit';
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ parent, depends }) => {
const { organization } = await parent();
const { organization, scopes } = await parent();
if(!scopes.includes('billing.read')) {
return redirect(301, `/console/organization-${organization.$id}`);
}
depends(Dependencies.PAYMENT_METHODS);
depends(Dependencies.ORGANIZATION);
depends(Dependencies.CREDIT);