@@ -8,21 +8,25 @@ import {
88} from "@/features/onboarding/communityOnboarding" ;
99import { initializeStarterChannels } from "@/features/onboarding/hooks" ;
1010import { useClaimInvite } from "@/features/onboarding/useClaimInvite" ;
11+ import { CommunityChangeOverlay } from "@/features/communities/ui/CommunityChangeOverlay" ;
1112import {
1213 takePendingWelcomeChannelForDirectEntry ,
1314 WELCOME_SURFACE_READY_EVENT ,
1415} from "@/features/onboarding/welcome" ;
16+ import { profileQueryKey } from "@/features/profile/hooks" ;
1517import { ProfileAvatar } from "@/features/profile/ui/ProfileAvatar" ;
1618import {
1719 parseEmojiAvatarDataUrl ,
1820 ProfileAvatarEditor ,
1921} from "@/features/profile/ui/ProfileAvatarEditor" ;
2022import { updateProfile } from "@/shared/api/tauriProfiles" ;
21- import { getIdentity } from "@/shared/api/tauriIdentity" ;
23+ import { getIdentity , importIdentity } from "@/shared/api/tauriIdentity" ;
2224import { listPersonas } from "@/shared/api/tauriPersonas" ;
25+ import { relayClient } from "@/shared/api/relayClient" ;
2326import type { AgentPersona } from "@/shared/api/types" ;
2427import { cn } from "@/shared/lib/cn" ;
2528import { Button } from "@/shared/ui/button" ;
29+ import { MembershipDenied } from "./MembershipDenied" ;
2630import { StartupWindowDragRegion } from "@/shared/ui/StartupWindowDragRegion" ;
2731import {
2832 ONBOARDING_PRIMARY_CTA_CLASS ,
@@ -35,6 +39,16 @@ import {
3539 ONBOARDING_KEY_TEXT_CLASS ,
3640} from "./NsecMaskedDisplay" ;
3741
42+ function isRelayMembershipDeniedError ( error : unknown ) : boolean {
43+ if ( ! ( error instanceof Error ) ) return false ;
44+ return (
45+ error . message . includes ( "You must be a relay member" ) ||
46+ error . message . includes ( "relay_membership_required" ) ||
47+ error . message . includes ( "restricted: not a relay member" ) ||
48+ error . message . includes ( "invalid: you are not a relay member" )
49+ ) ;
50+ }
51+
3852const STARTER_PERSONA_ANIMATIONS : Record < string , string > = {
3953 Fizz : "/onboarding/starter-team/fizz.png" ,
4054 Honey : "/onboarding/starter-team/honey.png" ,
@@ -113,6 +127,10 @@ export function CommunityOnboardingFlow({
113127 [ ] ,
114128 ) ;
115129 const [ isPending , setIsPending ] = React . useState ( false ) ;
130+ const [ deniedPubkey , setDeniedPubkey ] = React . useState ( "" ) ;
131+ const [ isMembershipDenied , setIsMembershipDenied ] = React . useState ( false ) ;
132+ const [ isCommunityChangeOpen , setIsCommunityChangeOpen ] =
133+ React . useState ( false ) ;
116134 const [ isCurtainFading , setIsCurtainFading ] = React . useState ( false ) ;
117135 const nameInputRef = React . useRef < HTMLInputElement | null > ( null ) ;
118136
@@ -228,6 +246,45 @@ export function CommunityOnboardingFlow({
228246
229247 if ( ! transaction ) return null ;
230248
249+ if ( isMembershipDenied ) {
250+ return (
251+ < >
252+ < MembershipDenied
253+ activeRelayUrl = { transaction . relayUrl }
254+ onBack = { ( ) => setIsMembershipDenied ( false ) }
255+ onChangeCommunity = { ( ) => setIsCommunityChangeOpen ( true ) }
256+ onImportKey = { async ( nsec ) => {
257+ const identity = await importIdentity ( nsec ) ;
258+ relayClient . disconnect ( ) ;
259+ queryClient . setQueryData ( [ "identity" ] , identity ) ;
260+ queryClient . removeQueries ( { queryKey : profileQueryKey } ) ;
261+ setIsMembershipDenied ( false ) ;
262+ update ( { stage : "connecting" , error : undefined } ) ;
263+ } }
264+ onRetry = { ( ) => {
265+ setIsMembershipDenied ( false ) ;
266+ update ( { stage : "connecting" , error : undefined } ) ;
267+ } }
268+ pubkey = { deniedPubkey }
269+ />
270+ { isCommunityChangeOpen ? (
271+ < CommunityChangeOverlay
272+ onClose = { ( ) => setIsCommunityChangeOpen ( false ) }
273+ onUpdated = { ( communityName , updatedRelayUrl ) => {
274+ update ( {
275+ communityName,
276+ relayUrl : updatedRelayUrl ,
277+ stage : "connecting" ,
278+ error : undefined ,
279+ } ) ;
280+ setIsMembershipDenied ( false ) ;
281+ } }
282+ />
283+ ) : null }
284+ </ >
285+ ) ;
286+ }
287+
231288 const saveProfile = async ( ) => {
232289 if ( ! displayName . trim ( ) ) return ;
233290 setIsPending ( true ) ;
@@ -238,6 +295,16 @@ export function CommunityOnboardingFlow({
238295 } ) ;
239296 update ( { stage : "team-intro" , error : undefined } ) ;
240297 } catch ( error ) {
298+ if ( isRelayMembershipDeniedError ( error ) ) {
299+ try {
300+ const identity = await getIdentity ( ) ;
301+ setDeniedPubkey ( identity . pubkey ) ;
302+ } catch {
303+ setDeniedPubkey ( "" ) ;
304+ }
305+ setIsMembershipDenied ( true ) ;
306+ return ;
307+ }
241308 update ( { error : error instanceof Error ? error . message : String ( error ) } ) ;
242309 } finally {
243310 setIsPending ( false ) ;
0 commit comments