MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / JoinContext

Function JoinContext

apps/web/contexts/Join.tsx:25–127  ·  view source on GitHub ↗
({ children }: Props)

Source from the content-addressed store, hash-verified

23};
24
25export const JoinContext = ({ children }: Props) => {
26 const [open, setOpen] = useState(false);
27 const [communityId, setCommunityId] = useState<string>();
28 const [flow, setFlow] = useState<AuthFlow>('signup');
29 const [mode, setMode] = useState<SignInMode>('magic');
30
31 const [callbackUrl, setCallbackUrl] = useState<string>();
32
33 useEffect(() => {
34 if (!callbackUrl) {
35 setCallbackUrl(window.location.href);
36 }
37 }, [callbackUrl]);
38
39 async function join({ communityId }: { communityId: string }) {
40 return await fetch('/api/invites/join-button', {
41 method: 'post',
42 body: JSON.stringify({
43 communityId,
44 }),
45 });
46 }
47
48 const startSignUp = async (props: StartSignUpProps) => {
49 setFlow(props.flow || 'signup');
50 setCommunityId(props.communityId);
51 setCallbackUrl(props.redirectUrl || window.location.href);
52 const session = await getSession();
53 if (session) {
54 const res = await join({ communityId: props.communityId });
55 if (res.ok) {
56 window.location.replace(props.redirectUrl || window.location.href);
57 return;
58 }
59 }
60 setOpen(!open);
61 };
62
63 const onSuccessfulSignIn = async () => {
64 const session = await getSession();
65 if (session && communityId) {
66 const res = await join({ communityId });
67 if (res.ok) {
68 window.location.replace(window.location.href);
69 return;
70 }
71 }
72 setOpen(false);
73 };
74
75 const onCloseModal = () => {
76 setOpen(false);
77 };
78
79 const mapText = {
80 signup: 'Sign up',
81 signin: 'Log in',
82 };

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected