tethys.backend/config/inertia.ts

79 lines
2.2 KiB
TypeScript

import { defineConfig } from '@adonisjs/inertia';
import type { HttpContext } from '@adonisjs/core/http';
import type { InferSharedProps } from '@adonisjs/inertia/types';
import env from '#start/env';
const inertiaConfig = defineConfig({
/**
* Path to the Edge view that will be used as the root view for Inertia responses
*/
rootView: 'app',
/**
* Data that should be shared with all rendered pages
*/
sharedData: {
//This will be available in all views
appName: 'Tethys Cloud',
errors: (ctx) => ctx.session?.flashMessages.get('errors'),
user_id: (ctx) => {
return ctx.session?.flashMessages.get('user_id');
},
opensearch_host: env.get('OPENSEARCH_HOST'),
flash: (ctx) => {
return {
message: ctx.session?.flashMessages.get('message'),
warning: ctx.session?.flashMessages.get('warning'),
error: ctx.session?.flashMessages.get('error'),
};
},
// params: ({ params }) => params,
authUser: async ({ auth }: HttpContext) => {
if (!auth?.user) return null
await auth.user.load('roles') // sicherstellen, dass geladen ist
return {
id: auth.user.id,
login: auth.user.login,
email: auth.user.email,
first_name: auth.user.first_name,
last_name: auth.user.last_name,
roles: auth.user.roles.map((role) => role.name),
}
},
},
/**
* Options for the server-side rendering
*/
ssr: {
enabled: false,
entrypoint: 'inertia/app/ssr.ts',
},
});
export default inertiaConfig
declare module '@adonisjs/inertia/types' {
export interface SharedProps extends InferSharedProps<typeof inertiaConfig> { }
}
// import { InertiaConfig } from '@ioc:EidelLev/Inertia';
// /*
// |--------------------------------------------------------------------------
// | Inertia-AdonisJS config
// |--------------------------------------------------------------------------
// |
// */
// export const inertia: InertiaConfig = {
// view: 'app',
// // ssr: {
// // enabled: false,
// // },
// };