Skip to content

Commit eabde95

Browse files
authored
Added callbackUrl to server user invitation (stack-auth#331)
1 parent 057dac1 commit eabde95

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

docs/fern/docs/pages/sdk/team.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ An invitation email containing a magic link will be sent to the specified user.
108108
<ParamField path="email" type="string" required>
109109
The email of the user to invite.
110110
</ParamField>
111+
112+
<ParamField path="callbackUrl" type="string">
113+
The URL where users will be redirected after accepting the team invitation.
114+
115+
Required when calling `inviteUser()` in the server environment since the URL cannot be automatically determined.
116+
117+
Example: `https://your-app-url.com/handler/team-invitation`
118+
</ParamField>
111119
</div>
112120
</ParamField>
113121
</div>

packages/stack/src/lib/stack-app.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,12 +753,15 @@ class _StackClientAppImpl<HasTokenStore extends boolean, ProjectId extends strin
753753
profileImageUrl: crud.profile_image_url,
754754
clientMetadata: crud.client_metadata,
755755
clientReadOnlyMetadata: crud.client_read_only_metadata,
756-
async inviteUser(options: { email: string }) {
756+
async inviteUser(options: { email: string, callbackUrl?: string }) {
757+
if (!options.callbackUrl && typeof window === "undefined") {
758+
throw new Error("Cannot invite user without a callback URL when calling the inviteUser function on the server.");
759+
}
757760
await app._interface.sendTeamInvitation({
758761
teamId: crud.id,
759762
email: options.email,
760763
session,
761-
callbackUrl: constructRedirectUrl(app.urls.teamInvitation),
764+
callbackUrl: options.callbackUrl ?? constructRedirectUrl(app.urls.teamInvitation),
762765
});
763766
},
764767
async listUsers() {
@@ -1959,12 +1962,16 @@ class _StackServerAppImpl<HasTokenStore extends boolean, ProjectId extends strin
19591962
});
19601963
await app._serverTeamMemberProfilesCache.refresh([crud.id]);
19611964
},
1962-
async inviteUser(options: { email: string }) {
1965+
async inviteUser(options: { email: string, callbackUrl?: string }) {
1966+
if (!options.callbackUrl && typeof window === "undefined") {
1967+
throw new Error("Cannot invite user without a callback URL when calling the inviteUser function on the server.");
1968+
}
1969+
19631970
await app._interface.sendTeamInvitation({
19641971
teamId: crud.id,
19651972
email: options.email,
19661973
session: null,
1967-
callbackUrl: constructRedirectUrl(app.urls.teamInvitation),
1974+
callbackUrl: options.callbackUrl ?? constructRedirectUrl(app.urls.teamInvitation),
19681975
});
19691976
},
19701977
};
@@ -3046,7 +3053,7 @@ export type Team = {
30463053
profileImageUrl: string | null,
30473054
clientMetadata: any,
30483055
clientReadOnlyMetadata: any,
3049-
inviteUser(options: { email: string }): Promise<void>,
3056+
inviteUser(options: { email: string, callbackUrl?: string }): Promise<void>,
30503057
listUsers(): Promise<TeamUser[]>,
30513058
useUsers(): TeamUser[],
30523059
update(update: TeamUpdateOptions): Promise<void>,
@@ -3092,7 +3099,7 @@ export type ServerTeam = {
30923099
update(update: ServerTeamUpdateOptions): Promise<void>,
30933100
delete(): Promise<void>,
30943101
addUser(userId: string): Promise<void>,
3095-
inviteUser(options: { email: string }): Promise<void>,
3102+
inviteUser(options: { email: string, callbackUrl?: string }): Promise<void>,
30963103
removeUser(userId: string): Promise<void>,
30973104
} & Team;
30983105

0 commit comments

Comments
 (0)