multi tenancy stuff

This commit is contained in:
m5r
2021-08-06 01:07:15 +08:00
parent b54f9ef43c
commit d20eeb0617
51 changed files with 907 additions and 2542 deletions

View File

@ -1,9 +1,10 @@
import { GlobalRole } from "db";
import { render } from "../../test/utils";
import Home from "./index";
import useCurrentCustomer from "../core/hooks/use-current-customer";
import useCurrentUser from "../core/hooks/use-current-user";
jest.mock("../core/hooks/use-current-customer");
const mockUseCurrentCustomer = useCurrentCustomer as jest.MockedFunction<typeof useCurrentCustomer>;
jest.mock("../core/hooks/use-current-user");
const mockUseCurrentUser = useCurrentUser as jest.MockedFunction<typeof useCurrentUser>;
test.skip("renders blitz documentation link", () => {
// This is an example of how to ensure a specific item is in the document
@ -11,16 +12,14 @@ test.skip("renders blitz documentation link", () => {
// when you remove the the default content from the page
// This is an example on how to mock api hooks when testing
mockUseCurrentCustomer.mockReturnValue({
customer: {
mockUseCurrentUser.mockReturnValue({
organization: undefined,
user: {
id: uuidv4(),
encryptionKey: "",
accountSid: null,
authToken: null,
twimlAppSid: null,
paddleCustomerId: null,
paddleSubscriptionId: null,
user: {} as any,
name: "name",
email: "email@test.com",
role: GlobalRole.CUSTOMER,
memberships: [],
},
hasFilledTwilioCredentials: false,
hasCompletedOnboarding: undefined,

View File

@ -4,7 +4,7 @@ import { Link, useMutation, Routes } from "blitz";
import BaseLayout from "../core/layouts/base-layout";
import logout from "../auth/mutations/logout";
import useCurrentCustomer from "../core/hooks/use-current-customer";
import useCurrentUser from "../core/hooks/use-current-user";
/*
* This file is just for a pleasant getting started page for your new app.
@ -12,10 +12,10 @@ import useCurrentCustomer from "../core/hooks/use-current-customer";
*/
const UserInfo = () => {
const { customer } = useCurrentCustomer();
const { user } = useCurrentUser();
const [logoutMutation] = useMutation(logout);
if (customer) {
if (user) {
return (
<>
<button
@ -27,9 +27,9 @@ const UserInfo = () => {
Logout
</button>
<div>
User id: <code>{customer.id}</code>
User id: <code>{user.id}</code>
<br />
User role: <code>{customer.encryptionKey}</code>
User role: <code>{user.role}</code>
</div>
</>
);