fix: permission issues
fix: white labaled version
This commit is contained in:
@@ -68,7 +68,8 @@ const schema = {
|
||||
};
|
||||
|
||||
const options = {
|
||||
schema
|
||||
schema,
|
||||
dotenv: true
|
||||
};
|
||||
fastify.register(env, options);
|
||||
if (!isDev) {
|
||||
@@ -76,7 +77,7 @@ if (!isDev) {
|
||||
root: path.join(__dirname, './public'),
|
||||
preCompressed: true
|
||||
});
|
||||
fastify.setNotFoundHandler(function (request, reply) {
|
||||
fastify.setNotFoundHandler({}, function (request, reply) {
|
||||
if (request.raw.url && request.raw.url.startsWith('/api')) {
|
||||
return reply.status(404).send({
|
||||
success: false
|
||||
|
||||
@@ -15,6 +15,9 @@ import { checkContainer, getEngine, removeContainer } from './docker';
|
||||
import { day } from './dayjs';
|
||||
import * as serviceFields from './serviceFields'
|
||||
|
||||
export const version = '3.0.4';
|
||||
export const isDev = process.env.NODE_ENV === 'development';
|
||||
|
||||
const algorithm = 'aes-256-ctr';
|
||||
const customConfig: Config = {
|
||||
dictionaries: [adjectives, colors, animals],
|
||||
@@ -22,8 +25,6 @@ const customConfig: Config = {
|
||||
separator: ' ',
|
||||
length: 3
|
||||
};
|
||||
export const isDev = process.env.NODE_ENV === 'development';
|
||||
export const version = '3.0.3';
|
||||
|
||||
export const defaultProxyImage = `coolify-haproxy-alpine:latest`;
|
||||
export const defaultProxyImageTcp = `coolify-haproxy-tcp-alpine:latest`;
|
||||
|
||||
19
apps/api/src/routes/api/v1/base/index.ts
Normal file
19
apps/api/src/routes/api/v1/base/index.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { FastifyPluginAsync } from 'fastify';
|
||||
import { errorHandler, version } from '../../../../lib/common';
|
||||
|
||||
const root: FastifyPluginAsync = async (fastify, opts): Promise<void> => {
|
||||
fastify.get('/', async (request) => {
|
||||
try {
|
||||
return {
|
||||
version,
|
||||
whiteLabeled: process.env.COOLIFY_WHITE_LABELED === 'true',
|
||||
whiteLabeledIcon: process.env.COOLIFY_WHITE_LABELED_ICON,
|
||||
}
|
||||
} catch ({ status, message }) {
|
||||
return errorHandler({ status, message })
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
export default root;
|
||||
@@ -258,11 +258,12 @@ export async function getCurrentUser(request: FastifyRequest, fastify) {
|
||||
include: { teams: true, permission: true }
|
||||
})
|
||||
if (user) {
|
||||
const permission = user.permission.find(p => p.teamId === request.query.teamId).permission
|
||||
const payload = {
|
||||
...request.user,
|
||||
teamId: request.query.teamId,
|
||||
permission: user.permission.find(p => p.teamId === request.query.teamId).permission || null,
|
||||
isAdmin: user.permission.find(p => p.teamId === request.query.teamId).permission === 'owner'
|
||||
permission: permission || null,
|
||||
isAdmin: permission === 'owner' || permission === 'admin'
|
||||
|
||||
}
|
||||
token = fastify.jwt.sign(payload)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { browser } from '$app/env';
|
||||
import { writable, readable, type Writable, type Readable } from 'svelte/store';
|
||||
// import { version as currentVersion } from '../../package.json';
|
||||
|
||||
interface AppSession {
|
||||
version: string
|
||||
version: string | null,
|
||||
userId: string | null,
|
||||
teamId: string | null,
|
||||
permission: string,
|
||||
@@ -18,7 +17,7 @@ interface AppSession {
|
||||
}
|
||||
export const loginEmail: Writable<string | undefined> = writable()
|
||||
export const appSession: Writable<AppSession> = writable({
|
||||
version: '3.0.3',
|
||||
version: null,
|
||||
userId: null,
|
||||
teamId: null,
|
||||
permission: 'read',
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
<script context="module" lang="ts">
|
||||
import type { Load } from '@sveltejs/kit';
|
||||
export const load: Load = async ({ url }) => {
|
||||
const baseSettings = await get('/base');
|
||||
try {
|
||||
if (Cookies.get('token')) {
|
||||
const response = await get(`/user`);
|
||||
return {
|
||||
props: {
|
||||
...response
|
||||
...response,
|
||||
baseSettings
|
||||
},
|
||||
stuff: {
|
||||
...response
|
||||
@@ -16,10 +18,17 @@
|
||||
if (url.pathname !== '/login' && url.pathname !== '/register') {
|
||||
return {
|
||||
status: 302,
|
||||
redirect: '/login'
|
||||
redirect: '/login',
|
||||
props: {
|
||||
baseSettings
|
||||
}
|
||||
};
|
||||
}
|
||||
return {};
|
||||
return {
|
||||
props: {
|
||||
baseSettings
|
||||
}
|
||||
};
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error?.code?.startsWith('FAST_JWT') || error.status === 401) {
|
||||
@@ -27,25 +36,39 @@
|
||||
if (url.pathname !== '/login') {
|
||||
return {
|
||||
status: 302,
|
||||
redirect: '/login'
|
||||
redirect: '/login',
|
||||
props: {
|
||||
baseSettings
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
if (url.pathname !== '/login') {
|
||||
return {
|
||||
status: 302,
|
||||
redirect: '/login'
|
||||
redirect: '/login',
|
||||
props: {
|
||||
baseSettings
|
||||
}
|
||||
};
|
||||
}
|
||||
return {
|
||||
status: 500,
|
||||
error: new Error(error)
|
||||
error: new Error(error),
|
||||
props: {
|
||||
baseSettings
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export let baseSettings: any;
|
||||
$appSession.version = baseSettings.version;
|
||||
$appSession.whiteLabeled = baseSettings.whiteLabeled;
|
||||
$appSession.whiteLabeledDetails.icon = baseSettings.whiteLabeledIcon;
|
||||
|
||||
export let settings: any;
|
||||
export let userId: string;
|
||||
export let teamId: string;
|
||||
@@ -54,7 +77,6 @@
|
||||
import '../tailwind.css';
|
||||
import Cookies from 'js-cookie';
|
||||
import { fade } from 'svelte/transition';
|
||||
|
||||
import { SvelteToast } from '@zerodevx/svelte-toast';
|
||||
import { navigating, page } from '$app/stores';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user