From 0f9cf194204fa4565cfa072eee7ae61b6fb9fc8c Mon Sep 17 00:00:00 2001 From: wil Date: Mon, 17 Jun 2024 22:10:25 -0400 Subject: [PATCH] no beta key = no access (#488) Co-authored-by: wil --- app/enums/authentication.ts | 2 +- app/hoc/withProtectedRoute.tsx | 2 +- app/routes/Login.tsx | 12 +++++++----- app/signals/authentication/fetchers.ts | 13 +++++++++---- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/app/enums/authentication.ts b/app/enums/authentication.ts index d575c047f3..ecd0425de0 100644 --- a/app/enums/authentication.ts +++ b/app/enums/authentication.ts @@ -7,7 +7,7 @@ export enum AUTH_STATUS { NO_ACCESS = "no_access", LOGGED_IN = "logged_in", LOGGING = "logging", - LOGGING2 = "logging_2", + GET_USER_INFO = "get_user_info", LOGGED_OUT = "logged_out", } diff --git a/app/hoc/withProtectedRoute.tsx b/app/hoc/withProtectedRoute.tsx index bd91942cac..35dfe224b9 100644 --- a/app/hoc/withProtectedRoute.tsx +++ b/app/hoc/withProtectedRoute.tsx @@ -20,7 +20,7 @@ export const withProtectionRoute =

( if ( status.value === AUTH_STATUS.INIT || status.value === AUTH_STATUS.LOGGING || - status.value === AUTH_STATUS.LOGGING2 + status.value === AUTH_STATUS.GET_USER_INFO ) { return (

diff --git a/app/routes/Login.tsx b/app/routes/Login.tsx index 2eed8bd247..4b806e3d03 100644 --- a/app/routes/Login.tsx +++ b/app/routes/Login.tsx @@ -26,6 +26,7 @@ export default function LoginScreen() { const { status: authStatus } = authentication; const authLoaderMessage = getAuthLoaderMessage(); const shouldShowLoader = checkShouldShowLoader(); + const showNoAccessModal = authStatus.value === AUTH_STATUS.NO_ACCESS; const handleOnSumbit = (ev: React.FormEvent) => { @@ -108,12 +109,12 @@ export default function LoginScreen() { text="We're in a closed beta and you'll need a beta key to use this app." title="Unauthorized" open={showNoAccessModal} - onClose={handleLogout} + onClose={handleClose} cancelText="Close" - onCancel={handleLogout} + onCancel={handleClose} okText="Get Beta Key" onOk={() => { - handleLogout(); + handleClose(); if (window) { window.open("https://storyteller.ai/beta-key/redeem", "_blank"); } @@ -124,11 +125,12 @@ export default function LoginScreen() { ); } -const handleLogout = () => { +const handleClose = () => { if (authentication.status.value !== AUTH_STATUS.LOGGED_OUT) { logout(); } }; + const checkShouldShowLoader = () => { return ( authentication.status.value === AUTH_STATUS.LOGGING || @@ -139,7 +141,7 @@ const getAuthLoaderMessage = () => { if (authentication.status.value === AUTH_STATUS.LOGGED_IN) { return "Authenticated, Redirecting..."; } - if (authentication.status.value === AUTH_STATUS.LOGGING2) { + if (authentication.status.value === AUTH_STATUS.GET_USER_INFO) { return "Getting User Info..."; } return "Getting Session..."; diff --git a/app/signals/authentication/fetchers.ts b/app/signals/authentication/fetchers.ts index d0dce27234..0dd764b19c 100644 --- a/app/signals/authentication/fetchers.ts +++ b/app/signals/authentication/fetchers.ts @@ -45,7 +45,7 @@ export const login = async ({ // technically user is login with the system now, HOWEVER, // in storyteller studio, only having a sesison is not enough, // we need session info and active subscription info as well - handleLoginPartTwo(); + getUserInfoAndSubcriptions(); }; export const persistLogin = async () => { @@ -53,11 +53,11 @@ export const persistLogin = async () => { if (authentication.status.value !== AUTH_STATUS.INIT) { return; } - handleLoginPartTwo(); + getUserInfoAndSubcriptions(); }; -async function handleLoginPartTwo() { - updateAuthStatus(AUTH_STATUS.LOGGING2); +async function getUserInfoAndSubcriptions() { + updateAuthStatus(AUTH_STATUS.GET_USER_INFO); const usersApi = new UsersApi(); const sessionResponse = await usersApi.GetSession(); if ( @@ -69,6 +69,11 @@ async function handleLoginPartTwo() { return; } + if (sessionResponse.data && !sessionResponse.data.user.can_access_studio) { + updateAuthStatus(AUTH_STATUS.NO_ACCESS); + return; + } + const billingApi = new BillingApi(); const subscriptionsResponse = await billingApi.ListActiveSubscriptions(); if (