Skip to content

Commit

Permalink
fix invitation logged out flow
Browse files Browse the repository at this point in the history
  • Loading branch information
a-type committed Nov 11, 2024
1 parent 71f26be commit 4e1b7ca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ router
.all('/gnocchi/*', rateLimit, gnocchiRouter.fetch)
.all('/wishWash/*', rateLimit, wishWashRouter.fetch);
// for local dev only, add endpoint to serve user files.
if (process.env.NODE_ENV === 'development') {
if (process.env.NODE_ENV !== 'production') {
router.get('/userFiles/:dir/:id/:filename', async (req) => {
try {
const filePath = join(
Expand Down
6 changes: 3 additions & 3 deletions web/src/components/plan/MembersAndInvitations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ export function MembersAndInvitations() {
{plan?.pendingInvitations.map((invite) => (
<CardRoot key={invite.id}>
<CardMain>
<Avatar />
<div className="flex flex-col gap-2 items-start justify-start">
<CardTitle className="flex-row mt-0 color-gray-7">
<Avatar />
<span>Invited: {invite.email}</span>
</div>
</CardTitle>
</CardMain>
<CardFooter>
<CardActions>
Expand Down
8 changes: 6 additions & 2 deletions web/src/pages/ClaimInvitePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ function ClaimInvitePage() {

const infoResult = useSuspenseQuery(claimInviteInfo, {
variables: { code },
// avoid error boundary when user is not logged in.
errorPolicy: 'ignore',
});

// redirect non-auth users to join
const isNotAuthenticated = infoResult.data && !infoResult.data.me;
const isNotAuthenticated = !infoResult.data?.me;
useEffect(() => {
if (isNotAuthenticated) {
navigate(`/login?returnTo=${encodeURIComponent(`/claim/${code}`)}`);
navigate(
`/login?tab=signup&returnTo=${encodeURIComponent(`/invite/${code}`)}&message=${encodeURIComponent('Sign up or log in to claim your invite.')}`,
);
}
}, [navigate, isNotAuthenticated, code]);

Expand Down
8 changes: 6 additions & 2 deletions web/src/pages/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default function LoginPage() {
}, [error]);

const activeTab = searchParams.get('tab') ?? 'signin';
const message = searchParams.get('message');

const [tosAgreed, setTosAgreed] = useState(false);

Expand Down Expand Up @@ -69,6 +70,9 @@ export default function LoginPage() {
</div>
<div className="flex flex-col gap-3 p-6 items-center bg-white border-solid border border-1 border-black rounded-lg relative z-1">
<h1 className="font-fancy mb-0">{title}</h1>
{message && (
<P className="px-3 py-1 rounded-full bg-accent-light">{message}</P>
)}
{appReferrer && (
<P className="italic color-gray-7 text-sm">A Biscuits.club app</P>
)}
Expand Down Expand Up @@ -113,7 +117,7 @@ export default function LoginPage() {
</label>
<OAuthSigninButton
endpoint={`${CONFIG.API_ORIGIN}/auth/provider/google/login`}
returnTo={'/settings?tab=subscription'}
returnTo={returnTo || '/settings?tab=subscription'}
inviteId={searchParams.get('inviteId')}
className="mx-auto"
disabled={!tosAgreed}
Expand All @@ -124,7 +128,7 @@ export default function LoginPage() {
<Or />
<EmailSignupForm
endpoint={`${CONFIG.API_ORIGIN}/auth/begin-email-signup`}
returnTo={'/settings?tab=subscription'}
returnTo={returnTo || '/settings?tab=subscription'}
disabled={!tosAgreed}
appState={appState}
/>
Expand Down

0 comments on commit 4e1b7ca

Please sign in to comment.