Skip to content

Commit

Permalink
Seamless workspace onboarding if domain activated with google signin (#…
Browse files Browse the repository at this point in the history
…1811)

* Seamless workspace onboarding if domain activated with google signin

* missing typing

* fix typo
  • Loading branch information
PopDaph authored Sep 27, 2023
1 parent 1bb0feb commit 36cf484
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
9 changes: 9 additions & 0 deletions front/lib/api/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import {
import { MembershipInvitationType } from "@app/types/membership_invitation";
import { UserType } from "@app/types/user";

export async function isWorkspaceAllowedOnDomain(wId: string) {
const workspace = await Workspace.findOne({
where: {
sId: wId,
},
});
return workspace && workspace.allowedDomain !== null;
}

/**
* Returns the users members of the workspace associated with the authenticator (without listing
* their own workspaces).
Expand Down
5 changes: 5 additions & 0 deletions front/pages/api/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ async function handler(
}

if (targetWorkspace) {
// For users joining a workspace from trying to access a conversation, we redirect to this conversation after signing in.
if (req.query.join === "true" && req.query.cId) {
res.redirect(`/w/${targetWorkspace.sId}/assistant/${req.query.cId}`);
return;
}
res.redirect(`/w/${targetWorkspace.sId}`);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion front/pages/w/[wId]/assistant/[cId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const getServerSideProps: GetServerSideProps<{
if (!owner || !auth.isUser() || !user) {
return {
redirect: {
destination: "/",
destination: `/w/${context.query.wId}/join?cId=${context.query.cId}`,
permanent: false,
},
};
Expand Down
91 changes: 91 additions & 0 deletions front/pages/w/[wId]/join.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { Logo } from "@dust-tt/sparkle";
import { GetServerSideProps, InferGetServerSidePropsType } from "next";
import { signIn } from "next-auth/react";

import { GoogleSignInButton } from "@app/components/Button";
import { isWorkspaceAllowedOnDomain } from "@app/lib/api/workspace";

const { URL = "", GA_TRACKING_ID = "" } = process.env;

export const getServerSideProps: GetServerSideProps<{
wId: string;
cId: string;
gaTrackingId: string;
baseUrl: string;
}> = async (context) => {
const wId = context.query.wId as string;
const cId = context.query.cId as string;

if (!wId || !cId) {
return {
notFound: true,
};
}

const isAllowedOnDomain = await isWorkspaceAllowedOnDomain(wId);
if (!isAllowedOnDomain) {
return {
redirect: {
destination: "/",
permanent: false,
},
};
}

return {
props: {
wId: wId,
cId: cId,
baseUrl: URL,
gaTrackingId: GA_TRACKING_ID,
},
};
};

export default function Join({
wId,
cId,
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
return (
<>
<div className="fixed bottom-0 left-0 right-0 top-0 -z-50 bg-slate-800" />
<main className="z-10 mx-6">
<div className="container mx-auto sm:max-w-3xl lg:max-w-4xl xl:max-w-5xl">
<div style={{ height: "10vh" }}></div>
<div className="grid grid-cols-1">
<div>
<Logo className="h-[48px] w-[192px] px-1" />
</div>
<p className="mt-16 font-objektiv text-4xl font-bold tracking-tighter text-slate-50 md:text-6xl">
<span className="text-red-400 sm:font-objektiv md:font-objektiv">
Secure AI assistant
</span>{" "}
<br />
with your company’s knowledge
<br />
</p>
</div>
<div className="h-10"></div>
<div>
<p className="font-regular mb-16 text-slate-400">
Glad to see you!
<br />
Please log in or sign up with your company email to access this
page.
</p>
<GoogleSignInButton
onClick={() =>
signIn("google", {
callbackUrl: `/api/login?wId=${wId}&cId=${cId}&join=true`,
})
}
>
<img src="/static/google_white_32x32.png" className="h-4 w-4" />
<span className="ml-2 mr-1">Sign in with Google</span>
</GoogleSignInButton>
</div>
</div>
</main>
</>
);
}

0 comments on commit 36cf484

Please sign in to comment.