anything-llm icon indicating copy to clipboard operation
anything-llm copied to clipboard

Error: Unexpected token 'U', "Unauthorized" is not valid JSON

Open bkowshik opened this issue 1 year ago • 6 comments

Get the following error when I try to create a new workspace.

Error: Unexpected token 'U', "Unauthorized" is not valid JSON

Screenshot 2024-01-04 at 10 12 20 AM

Steps

  1. Create a new invitation for a new user.
  2. In a Private window, open the invitation and signup as a new user.
  3. Create a new Workspace using the button in the onboarding.

bkowshik avatar Jan 04 '24 04:01 bkowshik

Ah, it is because you are clicking on the "Create First Workspace" in the messages in the default view, but in multi user mode the creation of workspaces for users is disabled, thus Unauthorized

As an admin, if you enabled "Users can create workspaces" in settings this would not longer occur.

timothycarambat avatar Jan 04 '24 06:01 timothycarambat

@timothycarambat Would you estimate this to be a Good first issue?

I would like to take a stab at making a contribution if possible, might need some support. I love this project and see myself contributing and this might be a good place to start.

bkowshik avatar Jan 04 '24 13:01 bkowshik

@bkowshik I think so!

In general, what needs to be check is if those buttons should display based on the user object which can be gotten from useUser hook. This only applies if the instance admin did not set the welcome messages to something custom.

https://github.com/Mintplex-Labs/anything-llm/blob/master/frontend/src/components/DefaultChat/index.jsx#L21

Add const {user} = useUser() to top of component.

Then in all places there is a CTA to create a workspace in the MESSAGES array you can change

 <button
    onClick={showNewWsModal}
    className="mt-5 w-fit transition-all duration-300 border border-slate-200 px-4 py-2 rounded-lg text-white text-sm items-center flex gap-x-2 hover:bg-slate-200 hover:text-slate-800 focus:ring-gray-800">
    <Plus className="h-4 w-4" />
    <p>Create your first workspace</p>
</button>

to

 {(!user || user?.role !== "default") && (
 <button
    onClick={showNewWsModal}
    className="mt-5 w-fit transition-all duration-300 border border-slate-200 px-4 py-2 rounded-lg text-white text-sm items-center flex gap-x-2 hover:bg-slate-200 hover:text-slate-800 focus:ring-gray-800">
       <Plus className="h-4 w-4" />
       <p>Create your first workspace</p>
 </button>
 )}

This will show the button when no user is defined (single user mode) and if the user is defined, such as in multi-user mode, make sure the role is not default. All new users are default when created unless otherwise specified by the admin. default users cannot create workspaces!

timothycarambat avatar Jan 04 '24 19:01 timothycarambat

@timothycarambat Can I work on this issue?

ElvinPero avatar Jan 04 '24 19:01 ElvinPero

@timothycarambat Can I work on this issue?

anyone can fix this issue!

KaushalSoniii avatar Jan 04 '24 19:01 KaushalSoniii

Whoever wants to work it just assign the issue to yourself so its not double-worked and somebody wastes their time :)

timothycarambat avatar Jan 04 '24 19:01 timothycarambat

closed by 5172bceec3f34b10ef4e96da0a6b659ccaee1f07

timothycarambat avatar Jan 09 '24 19:01 timothycarambat