Skip to content

Commit

Permalink
add invitation logic and ui
Browse files Browse the repository at this point in the history
  • Loading branch information
nikgraf committed Jun 6, 2024
1 parent ee05595 commit 0939ae3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 19 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ TODO better version where the token is also never exposed to the network so not

## Todos

- use expo-secure-store for the sessionKey
- encrypt MMKV storage on iOS and Android
- todo list UI & structure
- nav UI structure
- logo and colors
- deploy to production
- invitation links should expire after 2 days
- UI for invitations links

- figure out how author keys are managed (tabs in serenity and possible change in secsync)
- add retry for locker in case write fails (invalid clock)
- use expo-secure-store for the sessionKey
- encrypt MMKV storage on iOS and Android

- allow to delete list (needs a tombstone and properly cleanup local stores)
- allow to create lists locally

Expand Down
35 changes: 27 additions & 8 deletions apps/app/src/components/documentInvitation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,41 @@ export const DocumentInvitation: React.FC<Props> = ({
);
};

if (documentInvitationQuery.isLoading) {
return null;
}
if (documentInvitationQuery.error) {
return <Text>Couldn't load the Invitation</Text>;
}

return (
<div>
<Text>Invitation link</Text>
<div className="flex gap-2 pt-2">
<Input
id={id}
value={`${window.location.origin}/list-invitation/${documentInvitationQuery.data?.token}#key=${seed}`}
readOnly
className="w-72"
/>
{documentInvitationQuery.data ? (
<Text>
You have one invitation link ({documentInvitationQuery.data.token})
which is {documentInvitationQuery.data.isExpired ? "" : "not "}
expired.
</Text>
) : (
<Text>No invitation link found</Text>
)}

<Button
disabled={createOrRefreshDocumentInvitationMutation.isPending}
onPress={createAndSendInvitation}
>
<Text>Refresh</Text>
<Text>Create a new Invitation Link</Text>
</Button>
{seed && (
<Input
id={id}
value={`${window.location.origin}/list-invitation/${documentInvitationQuery.data?.token}#key=${seed}`}
readOnly
className="w-72 h-40"
multiline
/>
)}
</div>
</div>
);
Expand Down
10 changes: 6 additions & 4 deletions apps/server/src/db/getDocumentInvitationByToken.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { twoDaysAgo } from "../utils/twoDaysAgo.js";
import { prisma } from "./prisma.js";

type Params = {
token: string;
userId: string;
};

export const getDocumentInvitationByToken = async ({
token,
userId,
}: Params) => {
export const getDocumentInvitationByToken = async ({ token }: Params) => {
const documentInvitation = await prisma.documentInvitation.findUnique({
where: {
token,
// not older than 2 days
createdAt: {
gte: twoDaysAgo(),
},
},
});

Expand Down
13 changes: 11 additions & 2 deletions apps/server/src/trpc/appRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
publicProcedure,
router,
} from "../utils/trpc/trpc.js";
import { twoDaysAgo } from "../utils/twoDaysAgo.js";

export const appRouter = router({
me: protectedProcedure.query(async (opts) => {
Expand Down Expand Up @@ -125,7 +126,12 @@ export const appRouter = router({
documentId: opts.input.documentId,
ciphertext: boxCiphertext,
});
return documentInvitation ? { token: documentInvitation.token } : null;
return documentInvitation
? {
token: documentInvitation.token,
isExpired: documentInvitation.createdAt < twoDaysAgo(),
}
: null;
}),

documentInvitation: protectedProcedure
Expand All @@ -136,7 +142,10 @@ export const appRouter = router({
userId: opts.ctx.session.userId,
});
if (!documentInvitation) return null;
return { token: documentInvitation.token };
return {
token: documentInvitation.token,
isExpired: documentInvitation.createdAt < twoDaysAgo(),
};
}),

documentInvitationByToken: protectedProcedure
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/utils/twoDaysAgo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const twoDaysAgo = () => {
return new Date(Date.now() - 1000 * 60 * 60 * 24 * 2);
};

0 comments on commit 0939ae3

Please sign in to comment.