From dd7405baa0b9ed0c4471c816f3d97b8a71121b7c Mon Sep 17 00:00:00 2001 From: Shahar Glazner Date: Mon, 20 Nov 2023 14:18:00 +0200 Subject: [PATCH] fix: bugfix (#516) --- keep-ui/app/alerts/alerts.tsx | 3 ++- keep-ui/pages/api/auth/[...nextauth].ts | 5 ++++- keep-ui/utils/authenticationType.ts | 1 + keep/api/core/dependencies.py | 6 ++---- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/keep-ui/app/alerts/alerts.tsx b/keep-ui/app/alerts/alerts.tsx index 1d6c44f44..474a8fc9a 100644 --- a/keep-ui/app/alerts/alerts.tsx +++ b/keep-ui/app/alerts/alerts.tsx @@ -73,6 +73,7 @@ export default function Alerts({ useEffect(() => { if (tenantId) { + console.log("Connecting to pusher") const pusher = new Pusher(process.env.NEXT_PUBLIC_PUSHER_APP_KEY!, { wsHost: process.env.NEXT_PUBLIC_PUSHER_HOST, wsPort: process.env.NEXT_PUBLIC_PUSHER_PORT @@ -109,7 +110,7 @@ export default function Alerts({ channel.bind("async-done", function (data: any) { setIsAsyncLoading(false); }); - + console.log("Connected to pusher") return () => { pusher.unsubscribe(channelName); }; diff --git a/keep-ui/pages/api/auth/[...nextauth].ts b/keep-ui/pages/api/auth/[...nextauth].ts index 166f90d24..5ff7c2e4f 100644 --- a/keep-ui/pages/api/auth/[...nextauth].ts +++ b/keep-ui/pages/api/auth/[...nextauth].ts @@ -2,7 +2,7 @@ import NextAuth, { AuthOptions } from "next-auth"; import CredentialsProvider from "next-auth/providers/credentials"; import Auth0Provider from "next-auth/providers/auth0"; import { getApiURL } from "utils/apiUrl"; -import { AuthenticationType, NoAuthUserEmail } from "utils/authenticationType"; +import { AuthenticationType, NoAuthUserEmail, NoAuthTenant } from "utils/authenticationType"; const authType = process.env.AUTH_TYPE as AuthenticationType; /* @@ -145,6 +145,7 @@ const noAuthOptions = { id: 'keep-user-for-no-auth-purposes', name: 'Keep', email: NoAuthUserEmail, + tenantId: NoAuthTenant, accessToken: 'keep-token-for-no-auth-purposes', // Static token for no-auth purposes - DO NOT USE IN PRODUCTION }; }, @@ -155,11 +156,13 @@ const noAuthOptions = { // If the user object exists, set the static token if (user) { token.accessToken = user.accessToken; + token.tenantId = user.tenantId; } return token; }, async session({ session, token }) { session.accessToken = token.accessToken as string; + session.tenantId = token.tenantId as string; return session; }, }, diff --git a/keep-ui/utils/authenticationType.ts b/keep-ui/utils/authenticationType.ts index 2ab0abd69..905d5f87a 100644 --- a/keep-ui/utils/authenticationType.ts +++ b/keep-ui/utils/authenticationType.ts @@ -8,3 +8,4 @@ export enum AuthenticationType { } export const NoAuthUserEmail = "keep@example.com"; +export const NoAuthTenant = "keep"; diff --git a/keep/api/core/dependencies.py b/keep/api/core/dependencies.py index e0e4b52cd..e5e9e5007 100644 --- a/keep/api/core/dependencies.py +++ b/keep/api/core/dependencies.py @@ -143,10 +143,8 @@ def verify_bearer_token(token: str = Depends(oauth2_scheme)) -> str: def get_user_email_single_tenant(request: Request) -> str: # if we don't want to use authentication, return the single tenant id if ( - os.environ.get( - "AUTH_TYPE", - ) - == "false" + os.environ.get("AUTH_TYPE", AuthenticationType.NO_AUTH.value) + == AuthenticationType.NO_AUTH.value ): return SINGLE_TENANT_UUID