MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / acceptInvite

Function acceptInvite

apps/web/services/invites.ts:154–194  ·  view source on GitHub ↗
(id: string, email: string)

Source from the content-addressed store, hash-verified

152}
153
154export async function acceptInvite(id: string, email: string) {
155 const invite = await prisma.invites.findUnique({ where: { id } });
156 if (invite?.email !== email) {
157 throw { error: 'bad request, email mismatch' };
158 }
159 const auth = await prisma.auths.findUnique({ where: { email } });
160 if (!auth) {
161 throw { error: 'bad request, missing signup' };
162 }
163 const user = await prisma.users.findFirst({
164 include: { account: true },
165 where: { accountsId: invite.accountsId, authsId: auth.id },
166 });
167 if (user) {
168 return user;
169 }
170 const displayName = email.split('@').shift() || email;
171
172 const newUser = await prisma.users.create({
173 include: { account: true },
174 data: {
175 isAdmin: invite.role === Roles.ADMIN,
176 isBot: false,
177 account: { connect: { id: invite.accountsId } },
178 auth: { connect: { id: auth.id } },
179 anonymousAlias: generateRandomWordSlug(),
180 displayName,
181 role: invite.role,
182 },
183 });
184 // this step will be deprecated soon
185 await prisma.auths.update({
186 where: { email },
187 data: { account: { connect: { id: invite.accountsId } } },
188 });
189
190 await prisma.invites.update({ where: { id }, data: { status: 'ACCEPTED' } });
191
192 await eventUserJoin({ userId: newUser.id });
193 return newUser;
194}
195
196export async function updateInvitation({
197 inviteId,

Callers 4

handlerFunction · 0.90
handlerFunction · 0.90
handlerFunction · 0.90
acceptInvitesFunction · 0.90

Calls 4

generateRandomWordSlugFunction · 0.90
eventUserJoinFunction · 0.90
createMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected