/
githubmirror
/
tldraw
Обзор
Документация
Войти
/
githubmirror
/
tldraw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
apps/dotcom/sync-worker/src/utils/tla/getJoinableWorkspaceFromInvite.ts
32 строки
1 KB
Kevin Ingersoll
feat(dotcom): rework the manage workspace dialog (#9168)
17 июн 2026, 16:28
Не верифицирован
17 июн 2026, 16:28
abfa9f5
Код
Авторство
О чём код?
import { DB } from '@tldraw/dotcom-shared' import { Kysely } from 'kysely' /** * Resolve the workspace an invite token points to, or null if the token can't * be used to join: it's unknown/expired, the workspace is deleted, its invite * link is disabled, or it's a home workspace (group id === its owner's user id), * which is private. Callers treat null as an invalid token. */ export async function getJoinableWorkspaceFromInvite( db: Kysely<DB>, token: string ): Promise<{ id: string; name: string } | null> { const workspace = await db .selectFrom('group') .select(['id', 'name', 'isDeleted', 'inviteLinkEnabled']) .where('inviteSecret', '=', token) .executeTakeFirst() // A disabled invite link can't be used to join, but its secret is preserved so // re-enabling restores the same link. if (!workspace || workspace.isDeleted || workspace.inviteLinkEnabled === false) return null // A home workspace has the same id as its owning user. const homeOwner = await db .selectFrom('user') .select('id') .where('id', '=', workspace.id) .executeTakeFirst() if (homeOwner) return null return { id: workspace.id, name: workspace.name } }