mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 17:58:55 +00:00
no beta key = no access (#488)
Co-authored-by: wil <wil@storyteller.ai>
This commit is contained in:
1 parent
a2c82badbc
commit
0f9cf19420
4 files changed
+18
-11
No files matched your search
@@ -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",
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ export const withProtectionRoute = <P extends object>(
|
||||
if (
|
||||
status.value === AUTH_STATUS.INIT ||
|
||||
status.value === AUTH_STATUS.LOGGING ||
|
||||
status.value === AUTH_STATUS.LOGGING2
|
||||
status.value === AUTH_STATUS.GET_USER_INFO
|
||||
) {
|
||||
return (
|
||||
<div className="fixed flex h-full w-full flex-col items-center justify-center">
|
||||
|
||||
@@ -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<HTMLFormElement>) => {
|
||||
@@ -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...";
|
||||
|
||||
@@ -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 (
|
||||
|
||||
Reference in new issue
Block a user