Skip to content

Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.

[Feat]: Added demo accounts support (#591)

Ustatleen3c1401bcc62a
diff --git a/sdk/typescript/src/instrumentation/ollama/index.ts b/sdk/typescript/src/instrumentation/ollama/index.ts
new file mode 100644
index 00000000..5a10c399
--- /dev/null
+++ b/sdk/typescript/src/instrumentation/ollama/index.ts
@@ -0,0 +1,54 @@
+import {
+ InstrumentationBase,
+ InstrumentationModuleDefinition,
+ InstrumentationNodeModuleDefinition,
+ isWrapped,
+} from '@opentelemetry/instrumentation';
+import { InstrumentationConfig } from '@opentelemetry/instrumentation';
+import { INSTRUMENTATION_PREFIX } from '../../constant';
+import OllamaWrapper from './wrapper';
+
+export interface OllamaInstrumentationConfig extends InstrumentationConfig {}
+
+export default class OpenlitOllamaInstrumentation extends InstrumentationBase {
+ constructor(config: OllamaInstrumentationConfig = {}) {
+ super(`${INSTRUMENTATION_PREFIX}/instrumentation-ollama`, '1.0.0', config);
+ }
+
+ protected init(): void | InstrumentationModuleDefinition | InstrumentationModuleDefinition[] {
+ const module = new InstrumentationNodeModuleDefinition(
+ 'ollama',
+ ['>= 0.5.8'],
+ (moduleExports) => {
+ this._patch(moduleExports);
+ return moduleExports;
+ },
+ (moduleExports) => {
+ if (moduleExports !== undefined) {
+ this._unpatch(moduleExports);
+ }
+ }
+ );
+ return [module];
+ }
+
+ public manualPatch(ollama: any): void {
+ this._patch(ollama);
+ }
+
+ protected _patch(moduleExports: any) {
+ try {
+ if (isWrapped(moduleExports.Ollama.prototype.chat)) {
+ this._unwrap(moduleExports.Ollama.prototype, 'chat');
+ }
+
+ this._wrap(moduleExports.Ollama.prototype, 'chat', OllamaWrapper._patchChat(this.tracer));
+ } catch (e) {
+ console.error('Error in _patch method:', e);
+ }
+ }
+
+ protected _unpatch(moduleExports: any) {
+ this._unwrap(moduleExports.Ollama.prototype, 'chat');
+ }
+}
diff --git a/sdk/typescript/src/instrumentation/ollama/wrapper.ts b/sdk/typescript/src/instrumentation/ollama/wrapper.ts
new file mode 100644
index 00000000..f92568a9
--- /dev/null
+++ b/sdk/typescript/src/instrumentation/ollama/wrapper.ts
@@ -0,0 +1,270 @@
+import { Span, SpanKind, SpanStatusCode, Tracer, context, trace } from '@opentelemetry/api';
+import OpenlitConfig from '../../config';
+import OpenLitHelper from '../../helpers';
+import SemanticConvention from '../../semantic-convention';
+import { SDK_NAME, TELEMETRY_SDK_NAME } from '../../constant';
+
+export default class OllamaWrapper {
+ static setBaseSpanAttributes(
+ span: any,
+ { genAIEndpoint, model, user, cost, environment, applicationName }: any
+ ) {
+ span.setAttributes({
+ [TELEMETRY_SDK_NAME]: SDK_NAME,
+ });
+
+ span.setAttribute(TELEMETRY_SDK_NAME, SDK_NAME);
+ span.setAttribute(SemanticConvention.GEN_AI_SYSTEM, SemanticConvention.GEN_AI_SYSTEM_ANTHROPIC);
+ span.setAttribute(SemanticConvention.GEN_AI_ENDPOINT, genAIEndpoint);
+ span.setAttribute(SemanticConvention.GEN_AI_ENVIRONMENT, environment);
+ span.setAttribute(SemanticConvention.GEN_AI_APPLICATION_NAME, applicationName);
+ span.setAttribute(SemanticConvention.GEN_AI_REQUEST_MODEL, model);
+ span.setAttribute(SemanticConvention.GEN_AI_REQUEST_USER, user);
+ if (cost !== undefined) span.setAttribute(SemanticConvention.GEN_AI_USAGE_COST, cost);
+
+ span.setStatus({ code: SpanStatusCode.OK });
+ }
+
+ static _patchChat(tracer: Tracer): any {
+ const genAIEndpoint = 'ollama.chat';
+ return (originalMethod: (...args: any[]) => any) => {
+ return async function (this: any, ...args: any[]) {
+ const span = tracer.startSpan(genAIEndpoint, { kind: SpanKind.CLIENT });
+ const { stream = false } = args[0];
+ return context
+ .with(trace.setSpan(context.active(), span), async () => {
+ return originalMethod.apply(this, args);
+ })
+ .then((response) => {
+ if (!!stream) {
+ return OpenLitHelper.createStreamProxy(
+ response,
+ OllamaWrapper._chatGenerator({
+ args,
+ genAIEndpoint,
+ response,
+ span,
+ })
+ );
+ }
+
+ return OllamaWrapper._chat({ args, genAIEndpoint, response, span });
+ })
+ .catch((e: any) => {
+ OpenLitHelper.handleException(span, e);
+ span.end();
+ throw e;
+ });
+ };
+ };
+ }
+
+ static async _chat({
+ args,
+ genAIEndpoint,
+ response,
+ span,
+ }: {
+ args: any[];
+ genAIEndpoint: string;
+ response: any;
+ span: Span;
+ }) {
+ try {
+ await OllamaWrapper._chatCommonSetter({
+ args,
+ genAIEndpoint,
+ result: response,
+ span,
+ });
+ return response;
+ } catch (e: any) {
+ OpenLitHelper.handleException(span, e);
+ } finally {
+ span.end();
+ }
+ }
+
+ static async *_chatGenerator({
+ args,
+ genAIEndpoint,
+ response,
+ span,
+ }: {
+ args: any[];
+ genAIEndpoint: string;
+ response: any;
+ span: Span;
+ }) {
+ try {
+ const result = {
+ id: '0',
+ model: '',
+ stop_reason: '',
+ content: [
+ {
+ text: '',
+ role: '',
+ },
+ ],
+ usage: {
+ input_tokens: 0,
+ output_tokens: 0,
+ total_tokens: 0,
+ },
+ };
+ for await (const chunk of response) {
+ console.log(chunk);
+ switch (chunk.type) {
+ case 'content_block_delta':
+ result.content[0].text += chunk.delta?.text ?? '';
+ break;
+ case 'message_stop':
+ break;
+
+ case 'content_block_stop':
+ break;
+
+ case 'message_start':
+ if (chunk.message) {
+ result.id = chunk.message.id;
+ result.model = chunk.message.model;
+ result.content[0].role = chunk.message.role;
+ result.usage.input_tokens += Number(chunk.message.usage?.input_tokens) ?? 0;
+ result.usage.output_tokens += Number(chunk.message.usage?.output_tokens) ?? 0;
+ result.stop_reason = chunk.message?.stop_reason ?? '';
+ }
+ break;
+
+ case 'content_block_start':
+ result.content[0].text = chunk.content_block?.text ?? '';
+ break;
+ case 'message_delta':
+ result.stop_reason = chunk.delta?.stop_reason ?? '';
+ result.usage.output_tokens += Number(chunk.usage?.output_tokens) ?? 0;
+ break;
+ }
+
+ yield chunk;
+ }
+
+ result.usage.total_tokens = result.usage.output_tokens + result.usage.input_tokens;
+
+ await OllamaWrapper._chatCommonSetter({
+ args,
+ genAIEndpoint,
+ result,
+ span,
+ });
+ return response;
+ } catch (e: any) {
+ OpenLitHelper.handleException(span, e);
+ } finally {
+ span.end();
+ }
+ }
+
+ static async _chatCommonSetter({
+ args,
+ genAIEndpoint,
+ result,
+ span,
+ }: {
+ args: any[];
+ genAIEndpoint: string;
+ result: any;
+ span: Span;
+ }) {
+ const applicationName = OpenlitConfig.applicationName;
+ const environment = OpenlitConfig.environment;
+ const traceContent = OpenlitConfig.traceContent;
+ const {
+ messages,
+ max_tokens = null,
+ seed = null,
+ temperature = 1,
+ top_p,
+ top_k,
+ user,
+ stream = false,
+ stop_reason,
+ } = args[0];
+
+ // Format 'messages' into a single string
+ const messagePrompt = messages || '';
+ const formattedMessages = [];
+
+ for (const message of messagePrompt) {
+ const role = message.role;
+ const content = message.content;
+
+ if (Array.isArray(content)) {
+ const contentStr = content
+ .map((item) => {
+ if ('type' in item) {
+ return `${item.type}: ${item.text ? item.text : item.image_url}`;
+ } else {
+ return `text: ${item.text}`;
+ }
+ })
+ .join(', ');
+ formattedMessages.push(`${role}: ${contentStr}`);
+ } else {
+ formattedMessages.push(`${role}: ${content}`);
+ }
+ }
+
+ const prompt = formattedMessages.join('\n');
+ span.setAttribute(SemanticConvention.GEN_AI_TYPE, SemanticConvention.GEN_AI_TYPE_CHAT);
+ span.setAttribute(SemanticConvention.GEN_AI_RESPONSE_ID, result.id);
+
+ const model = result.model || args[0].model;
+
+ const pricingInfo = await OpenlitConfig.updatePricingJson(OpenlitConfig.pricing_json);
+
+ const promptTokens = result.prompt_eval_count;
+ const completionTokens = result.eval_count;
+ const totalTokens = promptTokens + completionTokens;
+
+ // Calculate cost of the operation
+ const cost = OpenLitHelper.getChatModelCost(model, pricingInfo, promptTokens, completionTokens);
+
+ OllamaWrapper.setBaseSpanAttributes(span, {
+ genAIEndpoint,
+ model,
+ user,
+ cost,
+ applicationName,
+ environment,
+ });
+
+ // Request Params attributes : Start
+ span.setAttribute(SemanticConvention.GEN_AI_REQUEST_TOP_P, top_p);
+ span.setAttribute(SemanticConvention.GEN_AI_REQUEST_TOP_K, top_k);
+ span.setAttribute(SemanticConvention.GEN_AI_REQUEST_MAX_TOKENS, max_tokens);
+ span.setAttribute(SemanticConvention.GEN_AI_REQUEST_TEMPERATURE, temperature);
+
+ span.setAttribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON, stop_reason);
+ span.setAttribute(SemanticConvention.GEN_AI_REQUEST_IS_STREAM, stream);
+ span.setAttribute(SemanticConvention.GEN_AI_REQUEST_SEED, seed);
+ if (traceContent) {
+ span.setAttribute(SemanticConvention.GEN_AI_CONTENT_PROMPT, prompt);
+ }
+ // Request Params attributes : End
+
+ span.setAttribute(SemanticConvention.GEN_AI_USAGE_PROMPT_TOKENS, promptTokens);
+ span.setAttribute(SemanticConvention.GEN_AI_USAGE_COMPLETION_TOKENS, completionTokens);
+ span.setAttribute(SemanticConvention.GEN_AI_USAGE_TOTAL_TOKENS, totalTokens);
+
+ if (result.done_reason) {
+ span.setAttribute(SemanticConvention.GEN_AI_RESPONSE_FINISH_REASON, result.done_reason);
+ }
+
+ if (traceContent) {
+ // Format 'messages' into a single string
+ const { message = {} } = result;
+ const messageString = `${message.role}: ${message.content}`;
+ span.setAttribute(SemanticConvention.GEN_AI_CONTENT_COMPLETION, messageString);
+ }
+ }
+}
diff --git a/src/client/.env.example b/src/client/.env.example
index 8e8db692..3a94747e 100644
--- a/src/client/.env.example
+++ b/src/client/.env.example
@@ -16,4 +16,9 @@ NEXTAUTH_URL=http://localhost:3000/
SQLITE_DATABASE_URL=
# TELEMETRY TRACKING
-TELEMETRY_ENABLED=true
\ No newline at end of file
+TELEMETRY_ENABLED=true
+
+
+# Demo accounts separated by comma :: Adding those you will be logged in automatically
+DEMO_ACCOUNT_EMAIL=
+DEMO_ACCOUNT_PASSWORD=
\ No newline at end of file
diff --git a/src/client/package-lock.json b/src/client/package-lock.json
index 5d249109..005604c9 100644
--- a/src/client/package-lock.json
+++ b/src/client/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "openlit",
- "version": "1.12.1",
+ "version": "1.12.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "openlit",
- "version": "1.12.1",
+ "version": "1.12.2",
"dependencies": {
"@anthropic-ai/sdk": "^0.21.1",
"@clickhouse/client": "^1.1.0",
@@ -41,6 +41,8 @@
"cohere-ai": "^7.10.5",
"copy-to-clipboard": "^3.3.3",
"date-fns": "^3.6.0",
+ "embla-carousel-autoplay": "^8.5.2",
+ "embla-carousel-react": "^8.5.2",
"generic-pool": "^3.9.0",
"js-tiktoken": "^1.0.12",
"lodash": "^4.17.21",
@@ -6053,6 +6055,39 @@
"integrity": "sha512-3D3DwWkRTzrdEpntY0hMLYwj7SeBk1138CkPE8sBDSj3WzrzOiG2rHm3luw8jucpf+WiyLBCZyU9lMHyQI9M9Q==",
"dev": true
},
+ "node_modules/embla-carousel": {
+ "version": "8.5.2",
+ "resolved": "https://registry.npmjs.org/embla-carousel/-/embla-carousel-8.5.2.tgz",
+ "integrity": "sha512-xQ9oVLrun/eCG/7ru3R+I5bJ7shsD8fFwLEY7yPe27/+fDHCNj0OT5EoG5ZbFyOxOcG6yTwW8oTz/dWyFnyGpg=="
+ },
+ "node_modules/embla-carousel-autoplay": {
+ "version": "8.5.2",
+ "resolved": "https://registry.npmjs.org/embla-carousel-autoplay/-/embla-carousel-autoplay-8.5.2.tgz",
+ "integrity": "sha512-27emJ0px3q/c0kCHCjwRrEbYcyYUPfGO3g5IBWF1i7714TTzE6L9P81V6PHLoSMAKJ1aHoT2e7YFOsuFKCbyag==",
+ "peerDependencies": {
+ "embla-carousel": "8.5.2"
+ }
+ },
+ "node_modules/embla-carousel-react": {
+ "version": "8.5.2",
+ "resolved": "https://registry.npmjs.org/embla-carousel-react/-/embla-carousel-react-8.5.2.tgz",
+ "integrity": "sha512-Tmx+uY3MqseIGdwp0ScyUuxpBgx5jX1f7od4Cm5mDwg/dptEiTKf9xp6tw0lZN2VA9JbnVMl/aikmbc53c6QFA==",
+ "dependencies": {
+ "embla-carousel": "8.5.2",
+ "embla-carousel-reactive-utils": "8.5.2"
+ },
+ "peerDependencies": {
+ "react": "^16.8.0 || ^17.0.1 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc"
+ }
+ },
+ "node_modules/embla-carousel-reactive-utils": {
+ "version": "8.5.2",
+ "resolved": "https://registry.npmjs.org/embla-carousel-reactive-utils/-/embla-carousel-reactive-utils-8.5.2.tgz",
+ "integrity": "sha512-QC8/hYSK/pEmqEdU1IO5O+XNc/Ptmmq7uCB44vKplgLKhB/l0+yvYx0+Cv0sF6Ena8Srld5vUErZkT+yTahtDg==",
+ "peerDependencies": {
+ "embla-carousel": "8.5.2"
+ }
+ },
"node_modules/emoji-regex": {
"version": "9.2.2",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz",
diff --git a/src/client/package.json b/src/client/package.json
index 392c7bf3..79f2341d 100644
--- a/src/client/package.json
+++ b/src/client/package.json
@@ -1,6 +1,6 @@
{
"name": "openlit",
- "version": "1.12.1",
+ "version": "1.12.2",
"private": true,
"scripts": {
"dev": "next dev",
@@ -43,6 +43,8 @@
"cohere-ai": "^7.10.5",
"copy-to-clipboard": "^3.3.3",
"date-fns": "^3.6.0",
+ "embla-carousel-autoplay": "^8.5.2",
+ "embla-carousel-react": "^8.5.2",
"generic-pool": "^3.9.0",
"js-tiktoken": "^1.0.12",
"lodash": "^4.17.21",
diff --git a/src/client/public/images/features/exception.png b/src/client/public/images/features/exception.png
new file mode 100644
index 00000000..cf208e68
Binary files /dev/null and b/src/client/public/images/features/exception.png differ
diff --git a/src/client/public/images/features/openground.png b/src/client/public/images/features/openground.png
new file mode 100644
index 00000000..c75f0ff2
Binary files /dev/null and b/src/client/public/images/features/openground.png differ
diff --git a/src/client/public/images/features/prompt.png b/src/client/public/images/features/prompt.png
new file mode 100644
index 00000000..14a04046
Binary files /dev/null and b/src/client/public/images/features/prompt.png differ
diff --git a/src/client/public/images/features/request.png b/src/client/public/images/features/request.png
new file mode 100644
index 00000000..6222fd68
Binary files /dev/null and b/src/client/public/images/features/request.png differ
diff --git a/src/client/public/images/features/vault.png b/src/client/public/images/features/vault.png
new file mode 100644
index 00000000..519da683
Binary files /dev/null and b/src/client/public/images/features/vault.png differ
diff --git a/src/client/src/app/(auth)/layout.tsx b/src/client/src/app/(auth)/layout.tsx
index 595f0266..be14216a 100644
--- a/src/client/src/app/(auth)/layout.tsx
+++ b/src/client/src/app/(auth)/layout.tsx
@@ -1,24 +1,20 @@
-"use client";
-import Image from "next/image";
+import AuthFormContainer from "@/components/(auth)/auth-form-container";
+import AutoSignInDemoInstance from "../../components/(auth)/auto-signin-demo-instance";
+import AuthDetailsCarousel from "@/components/(auth)/auth-details-carousel";
export default function AuthLayout({
children,
}: {
- children: React.ReactNode;
+ children: JSX.Element;
}) {
return (
- <div className="w-full lg:grid lg:grid-cols-2 h-screen">
- <div className="flex items-center justify-center py-12">{children}</div>
- <div className="flex flex-col items-center justify-center w-full h-full bg-stone-900">
- <Image
- src="/images/logo.png"
- alt="Image"
- width="200"
- height="200"
- className="object-cover"
- />
- <p className="text-stone-100 text-6xl">OpenLIT</p>
- </div>
+ <div className="min-h-screen grid lg:grid-cols-2 bg-white dark:bg-white">
+ <AuthDetailsCarousel />
+ <AuthFormContainer>
+ <AutoSignInDemoInstance demoCreds={{ email: process.env.DEMO_ACCOUNT_EMAIL, password: process.env.DEMO_ACCOUNT_PASSWORD }}>
+ {children}
+ </AutoSignInDemoInstance>
+ </AuthFormContainer>
</div>
);
}
diff --git a/src/client/src/app/page.tsx b/src/client/src/app/page.tsx
index 1736561c..547387c8 100644
--- a/src/client/src/app/page.tsx
+++ b/src/client/src/app/page.tsx
@@ -1,4 +1,5 @@
import { redirect } from "next/navigation";
+
export default async function Home() {
redirect("/dashboard");
}
diff --git a/src/client/src/components/(auth)/auth-details-carousel.tsx b/src/client/src/components/(auth)/auth-details-carousel.tsx
new file mode 100644
index 00000000..90078081
--- /dev/null
+++ b/src/client/src/components/(auth)/auth-details-carousel.tsx
@@ -0,0 +1,106 @@
+"use client";
+import Image from "next/image";
+import { Carousel, CarouselContent, CarouselItem } from "../ui/carousel";
+import { useEffect, useState } from "react";
+import Autoplay from "embla-carousel-autoplay";
+
+const features: { title: string; description: string; image: string }[] = [
+ {
+ title: "Application and Request Tracing",
+ description:
+ "Provides end-to-end tracing of requests across different providers to improve performance visibility.",
+ image: "/images/features/request.png",
+ },
+ {
+ title: "Track Application Errors",
+ description:
+ "Monitors and logs application errors to help detect and troubleshoot issues.",
+ image: "/images/features/exception.png",
+ },
+ {
+ title: "Openlit PlayGround",
+ description:
+ "Test and compare different LLMs side-by-side based on performance, cost, and other key metrics",
+ image: "/images/features/openground.png",
+ },
+ {
+ title: "Centralized Prompt Repository",
+ description:
+ "Allows for organized storage, versioning, and usage of prompts with dynamic variables across different applications.",
+ image: "/images/features/prompt.png",
+ },
+ {
+ title: "Secure Secrets Management",
+ description:
+ "Vault offers a secure way to store and manage sensitive application secrets.",
+ image: "/images/features/vault.png",
+ },
+];
+
+export default function AuthDetailsCarousel() {
+ const [api, setApi] = useState<any>();
+ const [current, setCurrent] = useState(0);
+ const autoplayPlugin = Autoplay({ playOnInit: true, delay: 3000 });
+
+ useEffect(() => {
+ if (!api) return;
+
+ api.on("select", () => {
+ setCurrent(api.selectedScrollSnap());
+ });
+ }, [api]);
+
+ return (
+ <div className="relative hidden lg:block bg-primary/[0.1]">
+ <div className="absolute top-8 left-8 z-10 flex items-center">
+ <Image
+ src="/images/logo.png"
+ alt="Image"
+ width="50"
+ height="50"
+ className="object-cover"
+ />
+ </div>
+ <Carousel
+ setApi={setApi}
+ plugins={[autoplayPlugin]}
+ className="w-full h-full"
+ opts={{
+ loop: true,
+ }}
+ >
+ <CarouselContent>
+ {features.map((feature, index) => (
+ <CarouselItem key={index} className="h-screen">
+ <div className="flex flex-col items-center justify-center h-full p-8 text-center">
+ <div className="relative w-full h-3/5 mb-2">
+ <Image
+ src={feature.image || "/placeholder.svg"}
+ alt={feature.title}
+ fill
+ className="object-contain"
+ />
+ </div>
+ <h2 className="text-2xl font-semibold mb-2">{feature.title}</h2>
+ <p className="max-w-md text-sm text-stone-500">
+ {feature.description}
+ </p>
+ </div>
+ </CarouselItem>
+ ))}
+ </CarouselContent>
+ <div className="absolute bottom-8 left-0 right-0 flex justify-center gap-2">
+ {features.map((_, index) => (
+ <button
+ key={index}
+ className={`w-2 h-2 rounded-full transition-all ${
+ current === index ? "bg-primary w-4" : "bg-primary/30"
+ }`}
+ onClick={() => api?.scrollTo(index)}
+ />
+ ))}
+ </div>
+ </Carousel>
+ </div>
+ );
+}
diff --git a/src/client/src/components/(auth)/auth-form-container.tsx b/src/client/src/components/(auth)/auth-form-container.tsx
new file mode 100644
index 00000000..981b0615
--- /dev/null
+++ b/src/client/src/components/(auth)/auth-form-container.tsx
@@ -0,0 +1,238 @@
+"use client";
+import { MoveRightIcon } from "lucide-react";
+import { GithubIcon } from "lucide-react";
+import { Button } from "../ui/button";
+import Link from "next/link";
+
+const Confetti = () => {
+ return (
+ <>
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.15]"
+ style={{
+ width: "97.6408px",
+ height: "97.6408px",
+ top: "2.70155%",
+ left: "47.1158%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.1]"
+ style={{
+ width: "56.3488px",
+ height: "56.3488px",
+ top: "5.21457%",
+ left: "26.7941%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.2]"
+ style={{
+ width: "83.3041px",
+ height: "83.3041px",
+ top: "78.102%",
+ left: "85.553%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.2]"
+ style={{
+ width: "73.5714px",
+ height: "73.5714px",
+ top: "54.351%",
+ left: "90.7616%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.05]"
+ style={{
+ width: "86.0302px",
+ height: "86.0302px",
+ top: "81.7666%",
+ left: "24.0279%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.1]"
+ style={{
+ width: "38.3342px",
+ height: "38.3342px",
+ top: "28.2189%",
+ left: "17.891%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.1]"
+ style={{
+ width: "101.238px",
+ height: "101.238px",
+ top: "49.6367%",
+ left: "60.0206%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.15]"
+ style={{
+ width: "92.0699px",
+ height: "92.0699px",
+ top: "16.2664%",
+ left: "13.4283%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.15]"
+ style={{
+ width: "28.6254px",
+ height: "28.6254px",
+ top: "47.9082%",
+ left: "18.7969%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.1]"
+ style={{
+ width: "62.0424px",
+ height: "62.0424px",
+ top: "15.3172%",
+ left: "68.8908%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.05]"
+ style={{
+ width: "37.4925px",
+ height: "37.4925px",
+ top: "32.3152%",
+ left: "71.9833%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.1]"
+ style={{
+ width: "66.0742px",
+ height: "66.0742px",
+ top: "11.2482%",
+ left: "3.57173%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.2]"
+ style={{
+ width: "78.706px",
+ height: "78.706px",
+ top: "11.0894%",
+ left: "74.244%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.2]"
+ style={{
+ width: "49.0052px",
+ height: "49.0052px",
+ top: "25.1587%",
+ left: "52.0703%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.01]"
+ style={{
+ width: "24.4747px",
+ height: "24.4747px",
+ top: "81.188%",
+ left: "65.8224%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.01]"
+ style={{
+ width: "102.344px",
+ height: "102.344px",
+ top: "75.5579%",
+ left: "92.4095%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.01]"
+ style={{
+ width: "29.7934px",
+ height: "29.7934px",
+ top: "92.546%",
+ left: "61.1729%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.2]"
+ style={{
+ width: "92.9791px",
+ height: "92.9791px",
+ top: "88.4441%",
+ left: "57.8831%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.05]"
+ style={{
+ width: "55.2333px",
+ height: "55.2333px",
+ top: "18.6437%",
+ left: "32.9982%",
+ }}
+ />
+ <div
+ className="absolute rounded-full bg-primary z-0 opacity-[0.15]"
+ style={{
+ width: "73.6121px",
+ height: "73.6121px",
+ top: "90.6981%",
+ left: "12.1542%",
+ }}
+ />
+ </>
+ );
+};
+
+export default function AuthFormContainer({
+ children,
+}: {
+ children: JSX.Element;
+}) {
+ return (
+ <div className="flex flex-col justify-center p-8 lg:p-16 bg-stone-50 relative">
+ <Confetti />
+ <div className="flex flex-col w-full max-w-sm mx-auto gap-12 z-10">
+ <div className="text-center">
+ <h1 className="text-4xl font-bold tracking-tight text-primary">
+ Welcome to OpenLIT
+ </h1>
+ <p className="text-stone-600">
+ Open Source Platform for AI Engineering
+ </p>
+ </div>
+ {children}
+ <div className="grid grid-cols-2 text-center text-sm">
+ <Link
+ href={"https://github.com/openlit/openlit"}
+ target="_blank"
+ className="w-full"
+ >
+ <Button
+ className={`w-full rounded-full gap-2 font-bold bg-stone-900 text-stone-50 hover:bg-stone-900/90 dark:bg-stone-900 dark:text-stone-50 dark:hover:bg-stone-900/90`}
+ >
+ Github
+ <GithubIcon className="ml-2 w-4" />
+ </Button>
+ </Link>
+ <Link
+ href="https://docs.openlit.io/latest/introduction"
+ target="_blank"
+ >
+ <Button variant={"ghost"} className="hover:bg-stone-100 hover:text-stone-900 dark:hover:bg-stone-100 dark:hover:text-stone-900">
+ <b>Documentation</b>
+ <MoveRightIcon className="ml-2 h-5 w-5" />
+ </Button>
+ </Link>
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/src/client/src/components/(auth)/auth-form.tsx b/src/client/src/components/(auth)/auth-form.tsx
index 10b0eca3..0176d11f 100644
--- a/src/client/src/components/(auth)/auth-form.tsx
+++ b/src/client/src/components/(auth)/auth-form.tsx
@@ -80,27 +80,19 @@ export function AuthForm({ type }: { type: "login" | "register" }) {
}
return (
- <div className="mx-auto grid gap-6 w-[350px] text-stone-900 dark:text-stone-100">
+ <div className="mx-auto grid gap-6 w-[350px] text-stone-900">
<div className="grid gap-2 text-center">
- <h1 className="text-3xl font-bold">
- {type === "login" ? "Login" : "Register"}
- </h1>
- <p className="text-balance text-muted-foreground">
- {type === "login"
- ? "Use your email and password to sign in"
- : "Create an account to enter"}
- </p>
</div>
{error && <SignInError error={error as keyof typeof errors} />}
<form
action={type === "login" ? login : register}
- className="flex flex-col space-y-4"
+ className="flex flex-col"
>
<div className="grid gap-4">
<div className="grid gap-2">
<Label htmlFor="email">Email</Label>
<Input
- className="ph-no-capture"
+ className="ph-no-capture dark:bg-white dark:border-stone-200"
id="email"
name="email"
type="email"
@@ -114,7 +106,7 @@ export function AuthForm({ type }: { type: "login" | "register" }) {
<Label htmlFor="password">Password</Label>
</div>
<Input
- className="ph-no-capture"
+ className="ph-no-capture dark:bg-white dark:border-stone-200"
autoComplete="current-password"
id="password"
name="password"
@@ -125,13 +117,13 @@ export function AuthForm({ type }: { type: "login" | "register" }) {
</div>
<Button
type="submit"
- className="w-full bg-primary dark:bg-primary text-white dark:text-white hover:dark:bg-primary"
+ className="w-full bg-primary dark:bg-primary text-white dark:text-white hover:dark:bg-primary rounded-full dark:hover:bg-stone-900/90"
>
{type === "login" ? "Sign in" : "Sign Up"}
</Button>
</div>
</form>
- <div className="mt-4 text-center text-sm">
+ <div className="text-center text-sm">
{type === "login"
? "Don't have an account? "
: "Already have an account?"}{" "}
diff --git a/src/client/src/components/(auth)/auto-signin-demo-instance.tsx b/src/client/src/components/(auth)/auto-signin-demo-instance.tsx
new file mode 100644
index 00000000..c4ac2e3c
--- /dev/null
+++ b/src/client/src/components/(auth)/auto-signin-demo-instance.tsx
@@ -0,0 +1,49 @@
+"use client";
+import { signIn } from "next-auth/react";
+import { useRouter } from "next/navigation";
+import { Loader2 } from "lucide-react"
+import { useEffect, useState } from "react";
+
+export default function AutoSignInDemoInstance({ children, demoCreds }: { children: JSX.Element, demoCreds: { email?: string, password?: string; } }) {
+ const router = useRouter()
+ const [err, setError] = useState<boolean>(false);
+ const setErrorLoginDemoAccount = () => {
+ setError(true);
+ window.localStorage.setItem("failedDemoLogin", "true");
+ };
+
+ useEffect(() => {
+ const failedDemoLogin = window.localStorage.getItem("failedDemoLogin");
+ if (failedDemoLogin !== "true") {
+ if (demoCreds.email && demoCreds.password) {
+ signIn("login", {
+ email: demoCreds.email,
+ password: demoCreds.password,
+ redirect: false,
+ }).then((obj) => {
+ if (obj?.status !== 200) {
+ setErrorLoginDemoAccount();
+ } else {
+ router.replace("/dashboard")
+ }
+ }).catch(() => {
+ setErrorLoginDemoAccount();
+ });
+ }
+ } else {
+ setError(true);
+ }
+ }, []);
+
+ if (demoCreds.email && demoCreds.password && !err) return (
+ <div className="flex flex-col items-center justify-center space-y-4 text-center">
+ <Loader2 className="h-8 w-8 animate-spin text-primary" />
+ <h2 className="text-2xl font-semibold">Setting Up Demo Account</h2>
+ <p className="text-muted-foreground">
+ Please wait while we prepare a demo account for you. This may take a few moments.
+ </p>
+ </div>
+ )
+
+ return children;
+}
\ No newline at end of file
diff --git a/src/client/src/components/(playground)/posthog.tsx b/src/client/src/components/(playground)/posthog.tsx
index 89ab0b4b..08101837 100644
--- a/src/client/src/components/(playground)/posthog.tsx
+++ b/src/client/src/components/(playground)/posthog.tsx
@@ -30,5 +30,5 @@ export default function CustomPostHogProvider({
);
}
- return children;
+ return children as JSX.Element;
}
diff --git a/src/client/src/components/ui/carousel.tsx b/src/client/src/components/ui/carousel.tsx
new file mode 100644
index 00000000..eee49fee
--- /dev/null
+++ b/src/client/src/components/ui/carousel.tsx
@@ -0,0 +1,262 @@
+"use client"
+
+import * as React from "react"
+import useEmblaCarousel, {
+ type UseEmblaCarouselType,
+} from "embla-carousel-react"
+import { ArrowLeft, ArrowRight } from "lucide-react"
+
+import { cn } from "@/lib/utils"
+import { Button } from "@/components/ui/button"
+
+type CarouselApi = UseEmblaCarouselType[1]
+type UseCarouselParameters = Parameters<typeof useEmblaCarousel>
+type CarouselOptions = UseCarouselParameters[0]
+type CarouselPlugin = UseCarouselParameters[1]
+
+type CarouselProps = {
+ opts?: CarouselOptions
+ plugins?: CarouselPlugin
+ orientation?: "horizontal" | "vertical"
+ setApi?: (api: CarouselApi) => void
+}
+
+type CarouselContextProps = {
+ carouselRef: ReturnType<typeof useEmblaCarousel>[0]
+ api: ReturnType<typeof useEmblaCarousel>[1]
+ scrollPrev: () => void
+ scrollNext: () => void
+ canScrollPrev: boolean
+ canScrollNext: boolean
+} & CarouselProps
+
+const CarouselContext = React.createContext<CarouselContextProps | null>(null)
+
+function useCarousel() {
+ const context = React.useContext(CarouselContext)
+
+ if (!context) {
+ throw new Error("useCarousel must be used within a <Carousel />")
+ }
+
+ return context
+}
+
+const Carousel = React.forwardRef<
+ HTMLDivElement,
+ React.HTMLAttributes<HTMLDivElement> & CarouselProps
+>(
+ (
+ {
+ orientation = "horizontal",
+ opts,
+ setApi,
+ plugins,
+ className,
+ children,
+ ...props
+ },
+ ref
+ ) => {
+ const [carouselRef, api] = useEmblaCarousel(
+ {
+ ...opts,
+ axis: orientation === "horizontal" ? "x" : "y",
+ },
+ plugins
+ )
+ const [canScrollPrev, setCanScrollPrev] = React.useState(false)
+ const [canScrollNext, setCanScrollNext] = React.useState(false)
+
+ const onSelect = React.useCallback((api: CarouselApi) => {
+ if (!api) {
+ return
+ }
+
+ setCanScrollPrev(api.canScrollPrev())
+ setCanScrollNext(api.canScrollNext())
+ }, [])
+
+ const scrollPrev = React.useCallback(() => {
+ api?.scrollPrev()
+ }, [api])
+
+ const scrollNext = React.useCallback(() => {
+ api?.scrollNext()
+ }, [api])
+
+ const handleKeyDown = React.useCallback(
+ (event: React.KeyboardEvent<HTMLDivElement>) => {
+ if (event.key === "ArrowLeft") {
+ event.preventDefault()
+ scrollPrev()
+ } else if (event.key === "ArrowRight") {
+ event.preventDefault()
+ scrollNext()
+ }
+ },
+ [scrollPrev, scrollNext]
+ )
+
+ React.useEffect(() => {
+ if (!api || !setApi) {
+ return
+ }
+
+ setApi(api)
+ }, [api, setApi])
+
+ React.useEffect(() => {
+ if (!api) {
+ return
+ }
+
+ onSelect(api)
+ api.on("reInit", onSelect)
+ api.on("select", onSelect)
+
+ return () => {
+ api?.off("select", onSelect)
+ }
+ }, [api, onSelect])
+
+ return (
+ <CarouselContext.Provider
+ value={{
+ carouselRef,
+ api: api,
+ opts,
+ orientation:
+ orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
+ scrollPrev,
+ scrollNext,
+ canScrollPrev,
+ canScrollNext,
+ }}
+ >
+ <div
+ ref={ref}
+ onKeyDownCapture={handleKeyDown}
+ className={cn("relative", className)}
+ role="region"
+ aria-roledescription="carousel"
+ {...props}
+ >
+ {children}
+ </div>
+ </CarouselContext.Provider>
+ )
+ }
+)
+Carousel.displayName = "Carousel"
+
+const CarouselContent = React.forwardRef<
+ HTMLDivElement,
+ React.HTMLAttributes<HTMLDivElement>
+>(({ className, ...props }, ref) => {
+ const { carouselRef, orientation } = useCarousel()
+
+ return (
+ <div ref={carouselRef} className="overflow-hidden">
+ <div
+ ref={ref}
+ className={cn(
+ "flex",
+ orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col",
+ className
+ )}
+ {...props}
+ />
+ </div>
+ )
+})
+CarouselContent.displayName = "CarouselContent"
+
+const CarouselItem = React.forwardRef<
+ HTMLDivElement,
+ React.HTMLAttributes<HTMLDivElement>
+>(({ className, ...props }, ref) => {
+ const { orientation } = useCarousel()
+
+ return (
+ <div
+ ref={ref}
+ role="group"
+ aria-roledescription="slide"
+ className={cn(
+ "min-w-0 shrink-0 grow-0 basis-full",
+ orientation === "horizontal" ? "pl-4" : "pt-4",
+ className
+ )}
+ {...props}
+ />
+ )
+})
+CarouselItem.displayName = "CarouselItem"
+
+const CarouselPrevious = React.forwardRef<
+ HTMLButtonElement,
+ React.ComponentProps<typeof Button>
+>(({ className, variant = "outline", size = "icon", ...props }, ref) => {
+ const { orientation, scrollPrev, canScrollPrev } = useCarousel()
+
+ return (
+ <Button
+ ref={ref}
+ variant={variant}
+ size={size}
+ className={cn(
+ "absolute h-8 w-8 rounded-full",
+ orientation === "horizontal"
+ ? "-left-12 top-1/2 -translate-y-1/2"
+ : "-top-12 left-1/2 -translate-x-1/2 rotate-90",
+ className
+ )}
+ disabled={!canScrollPrev}
+ onClick={scrollPrev}
+ {...props}
+ >
+ <ArrowLeft className="h-4 w-4" />
+ <span className="sr-only">Previous slide</span>
+ </Button>
+ )
+})
+CarouselPrevious.displayName = "CarouselPrevious"
+
+const CarouselNext = React.forwardRef<
+ HTMLButtonElement,
+ React.ComponentProps<typeof Button>
+>(({ className, variant = "outline", size = "icon", ...props }, ref) => {
+ const { orientation, scrollNext, canScrollNext } = useCarousel()
+
+ return (
+ <Button
+ ref={ref}
+ variant={variant}
+ size={size}
+ className={cn(
+ "absolute h-8 w-8 rounded-full",
+ orientation === "horizontal"
+ ? "-right-12 top-1/2 -translate-y-1/2"
+ : "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
+ className
+ )}
+ disabled={!canScrollNext}
+ onClick={scrollNext}
+ {...props}
+ >
+ <ArrowRight className="h-4 w-4" />
+ <span className="sr-only">Next slide</span>
+ </Button>
+ )
+})
+CarouselNext.displayName = "CarouselNext"
+
+export {
+ type CarouselApi,
+ Carousel,
+ CarouselContent,
+ CarouselItem,
+ CarouselPrevious,
+ CarouselNext,
+}
\ No newline at end of file
diff --git a/src/client/src/constants/route.ts b/src/client/src/constants/route.ts
index a01c6a6c..b2ec2b18 100644
--- a/src/client/src/constants/route.ts
+++ b/src/client/src/constants/route.ts
@@ -2,5 +2,11 @@ export const DEFAULT_LOGGED_IN_ROUTE = "/getting-started";
export const ALLOWED_OPENLIT_ROUTES_WITHOUT_TOKEN = [
"/api/prompt/get-compiled",
"/api/vault/get-secrets",
- "/api/telemetry-enabled",
];
+
+// Route format is methodtype: routepathregex[]
+export const RESTRICTED_DEMO_ACCOUNT_ROUTES: Record<string, string[]> = {
+ POST: ["/api/db-config", "/api/user/profile"],
+ PUT: ["/api/db-config", "/api/vault"],
+ DELETE: ["/api/db-config", "/api/api-key", "/api/vault", "/api/prompt-hub"],
+};
diff --git a/src/client/src/middleware.ts b/src/client/src/middleware.ts
index 15518118..2a8321d1 100644
--- a/src/client/src/middleware.ts
+++ b/src/client/src/middleware.ts
@@ -1,65 +1,12 @@
-import { getToken } from "next-auth/jwt";
-import { withAuth } from "next-auth/middleware";
-import { NextResponse } from "next/server";
-import {
- DEFAULT_LOGGED_IN_ROUTE,
- ALLOWED_OPENLIT_ROUTES_WITHOUT_TOKEN,
-} from "@/constants/route";
+import { chain } from "@/middleware/chain";
+import checkAuth from "@/middleware/check-auth";
+import checkDemoAccount from "@/middleware/check-demo-account";
-export default withAuth(
- async function middleware(req) {
- const pathname = req.nextUrl.pathname;
- if (
- pathname.startsWith("/_next") ||
- pathname.startsWith("/static") ||
- pathname.startsWith("/images")
- )
- return NextResponse.next();
-
- const token = await getToken({ req });
- const isAuth = !!token;
- const isAllowedRequestWithoutToken =
- ALLOWED_OPENLIT_ROUTES_WITHOUT_TOKEN.includes(pathname);
- const isAuthPage =
- pathname.startsWith("/login") || pathname.startsWith("/register");
- const isApiPage = pathname.startsWith("/api");
-
- if (isAuthPage) {
- if (isAuth) {
- return NextResponse.redirect(new URL(DEFAULT_LOGGED_IN_ROUTE, req.url));
- }
-
- return null;
- }
-
- if (isApiPage) {
- if (isAuth || isAllowedRequestWithoutToken) {
- return NextResponse.next();
- }
- }
-
- if (!isAuth) {
- let from = pathname;
- if (req.nextUrl.search) {
- from += req.nextUrl.search;
- }
-
- return NextResponse.redirect(
- new URL(`/login?callbackUrl=${encodeURIComponent(from)}`, req.url)
- );
- }
- },
- {
- callbacks: {
- authorized() {
- // This is a work-around for handling redirect on auth pages.
- // We return true here so that the middleware function above
- // is always called.
- return true;
- },
- },
- }
-);
+export const middleware = chain([
+ checkDemoAccount,
+ // @ts-expect-error Type 'NextMiddlewareWithAuth' is not assignable to type 'NextMiddleware'.
+ checkAuth,
+]);
export const config = {
matcher: [
@@ -75,6 +22,5 @@ export const config = {
"/prompt-hub",
"/vault",
"/api-keys",
- "/telemetry-enabled",
],
};
diff --git a/src/client/src/middleware/chain.ts b/src/client/src/middleware/chain.ts
new file mode 100644
index 00000000..e6069973
--- /dev/null
+++ b/src/client/src/middleware/chain.ts
@@ -0,0 +1,17 @@
+import { NextMiddleware } from 'next/server';
+import { NextResponse } from 'next/server';
+import { MiddlewareFactory } from './middlewareFactory';
+
+export function chain(
+ functions: MiddlewareFactory[],
+ index = 0
+): NextMiddleware {
+ const current = functions[index];
+
+ if (current) {
+ const next = chain(functions, index + 1);
+ return current(next);
+ }
+
+ return NextResponse.next;
+}
\ No newline at end of file
diff --git a/src/client/src/middleware/check-auth.ts b/src/client/src/middleware/check-auth.ts
new file mode 100644
index 00000000..e2c63a98
--- /dev/null
+++ b/src/client/src/middleware/check-auth.ts
@@ -0,0 +1,64 @@
+import { withAuth } from "next-auth/middleware"
+import { getToken } from "next-auth/jwt";
+import { NextFetchEvent, NextMiddleware, NextRequest, NextResponse } from "next/server";
+import {
+ DEFAULT_LOGGED_IN_ROUTE,
+ ALLOWED_OPENLIT_ROUTES_WITHOUT_TOKEN,
+} from "@/constants/route";
+
+export default function checkAuth(next: NextMiddleware) {
+ return withAuth(async function middleware(request: NextRequest, _next: NextFetchEvent) {
+ const pathname = request.nextUrl.pathname;
+ if (
+ pathname.startsWith("/_next") ||
+ pathname.startsWith("/static") ||
+ pathname.startsWith("/images")
+ ) {
+ return next(request, _next);
+ }
+
+ const token = await getToken({ req: request });
+ const isAuth = !!token;
+ const isAllowedRequestWithoutToken =
+ ALLOWED_OPENLIT_ROUTES_WITHOUT_TOKEN.includes(pathname);
+ const isAuthPage =
+ pathname.startsWith("/login") || pathname.startsWith("/register");
+ const isApiPage = pathname.startsWith("/api");
+
+ if (isAuthPage) {
+ if (isAuth) {
+ return NextResponse.redirect(new URL(DEFAULT_LOGGED_IN_ROUTE, request.url));
+ }
+
+ return NextResponse.next();
+ }
+
+ if (isApiPage) {
+ if (isAuth || isAllowedRequestWithoutToken) {
+ return NextResponse.next();
+ }
+ }
+
+ if (!isAuth) {
+ let from = pathname;
+ if (request.nextUrl.search) {
+ from += request.nextUrl.search;
+ }
+
+ return NextResponse.redirect(
+ new URL(`/login?callbackUrl=${encodeURIComponent(from)}`, request.url)
+ );
+ }
+
+ return NextResponse.next();
+ }, {
+ callbacks: {
+ async authorized() {
+ // This is a work-around for handling redirect on auth pages.
+ // We return true here so that the middleware function above
+ // is always called.
+ return true;
+ },
+ },
+ })
+}
diff --git a/src/client/src/middleware/check-demo-account.ts b/src/client/src/middleware/check-demo-account.ts
new file mode 100644
index 00000000..22662e86
--- /dev/null
+++ b/src/client/src/middleware/check-demo-account.ts
@@ -0,0 +1,26 @@
+import { NextFetchEvent, NextMiddleware, NextResponse } from 'next/server';
+import type { NextRequest } from 'next/server';
+import { RESTRICTED_DEMO_ACCOUNT_ROUTES } from '@/constants/route';
+import { getToken } from 'next-auth/jwt';
+
+
+export default function checkDemoAccount(next: NextMiddleware) {
+ return async (
+ request: NextRequest,
+ _next: NextFetchEvent
+ ) => {
+ if (process.env.DEMO_ACCOUNT_EMAIL) {
+ const pathname = request.nextUrl.pathname;
+ if (RESTRICTED_DEMO_ACCOUNT_ROUTES[request.method]?.some((regex) => (new RegExp(regex)).test(pathname))) {
+ const token = await getToken({ req: request });
+ if (process.env.DEMO_ACCOUNT_EMAIL.toLowerCase() === token?.email?.toLowerCase()) {
+ return NextResponse.json("This Action is not allowed for demo accounts!",
+ { status: 403 }
+ );
+ }
+ }
+ }
+
+ return next(request, _next);
+ };
+}
\ No newline at end of file
diff --git a/src/client/src/middleware/middlewareFactory.ts b/src/client/src/middleware/middlewareFactory.ts
new file mode 100644
index 00000000..849bef1d
--- /dev/null
+++ b/src/client/src/middleware/middlewareFactory.ts
@@ -0,0 +1,3 @@
+import { NextMiddleware } from "next/server";
+
+export type MiddlewareFactory = (middleware: NextMiddleware) => NextMiddleware;
\ No newline at end of file
diff --git a/src/client/tsconfig.json b/src/client/tsconfig.json
index b9ca20bd..56d7f22d 100644
--- a/src/client/tsconfig.json
+++ b/src/client/tsconfig.json
@@ -29,6 +29,7 @@
"@/store/*": ["./src/store/*"],
"@/helpers/*": ["./src/helpers/*"],
"@/selectors/*": ["./src/selectors/*"],
+ "@/middleware/*": ["./src/middleware/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "prisma/seed.js"],