Added callbackUrl to server user invitation (#331)

This commit is contained in:
Zai Shi 2024-11-08 14:05:08 +01:00 committed by GitHub
parent 057dac1a66
commit eabde95a32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 6 deletions

View File

@ -108,6 +108,14 @@ An invitation email containing a magic link will be sent to the specified user.
<ParamField path="email" type="string" required>
The email of the user to invite.
</ParamField>
<ParamField path="callbackUrl" type="string">
The URL where users will be redirected after accepting the team invitation.
Required when calling `inviteUser()` in the server environment since the URL cannot be automatically determined.
Example: `https://your-app-url.com/handler/team-invitation`
</ParamField>
</div>
</ParamField>
</div>

View File

@ -753,12 +753,15 @@ class _StackClientAppImpl<HasTokenStore extends boolean, ProjectId extends strin
profileImageUrl: crud.profile_image_url,
clientMetadata: crud.client_metadata,
clientReadOnlyMetadata: crud.client_read_only_metadata,
async inviteUser(options: { email: string }) {
async inviteUser(options: { email: string, callbackUrl?: string }) {
if (!options.callbackUrl && typeof window === "undefined") {
throw new Error("Cannot invite user without a callback URL when calling the inviteUser function on the server.");
}
await app._interface.sendTeamInvitation({
teamId: crud.id,
email: options.email,
session,
callbackUrl: constructRedirectUrl(app.urls.teamInvitation),
callbackUrl: options.callbackUrl ?? constructRedirectUrl(app.urls.teamInvitation),
});
},
async listUsers() {
@ -1959,12 +1962,16 @@ class _StackServerAppImpl<HasTokenStore extends boolean, ProjectId extends strin
});
await app._serverTeamMemberProfilesCache.refresh([crud.id]);
},
async inviteUser(options: { email: string }) {
async inviteUser(options: { email: string, callbackUrl?: string }) {
if (!options.callbackUrl && typeof window === "undefined") {
throw new Error("Cannot invite user without a callback URL when calling the inviteUser function on the server.");
}
await app._interface.sendTeamInvitation({
teamId: crud.id,
email: options.email,
session: null,
callbackUrl: constructRedirectUrl(app.urls.teamInvitation),
callbackUrl: options.callbackUrl ?? constructRedirectUrl(app.urls.teamInvitation),
});
},
};
@ -3046,7 +3053,7 @@ export type Team = {
profileImageUrl: string | null,
clientMetadata: any,
clientReadOnlyMetadata: any,
inviteUser(options: { email: string }): Promise<void>,
inviteUser(options: { email: string, callbackUrl?: string }): Promise<void>,
listUsers(): Promise<TeamUser[]>,
useUsers(): TeamUser[],
update(update: TeamUpdateOptions): Promise<void>,
@ -3092,7 +3099,7 @@ export type ServerTeam = {
update(update: ServerTeamUpdateOptions): Promise<void>,
delete(): Promise<void>,
addUser(userId: string): Promise<void>,
inviteUser(options: { email: string }): Promise<void>,
inviteUser(options: { email: string, callbackUrl?: string }): Promise<void>,
removeUser(userId: string): Promise<void>,
} & Team;