Stirling-Tools/Stirling-PDF · error · Error
No current team
Error message
No current team
What it means
Thrown by SaaSTeamContext.inviteUser() when currentTeam is null/undefined. The function immediately needs currentTeam.teamId to POST to /api/v1/team/invite. This fires when the team context hasn't loaded yet or the user genuinely has no current team selected.
Source
Thrown at frontend/editor/src/cloud/contexts/SaaSTeamContext.tsx:199
useEffect(() => {
if (currentTeam && !currentTeam.isPersonal) {
fetchTeamMembers(currentTeam.teamId);
// Only fetch invitations if user is team leader
if (currentTeam.isLeader) {
fetchTeamInvitations(currentTeam.teamId);
} else {
setTeamInvitations([]);
}
} else {
setTeamMembers([]);
setTeamInvitations([]);
}
setLoading(false);
}, [currentTeam, fetchTeamMembers, fetchTeamInvitations]);
const inviteUser = async (email: string) => {
if (!currentTeam) throw new Error("No current team");
await apiClient.post("/api/v1/team/invite", {
teamId: currentTeam.teamId,
email,
});
await fetchTeamInvitations(currentTeam.teamId);
};
const refreshTeams = useCallback(async () => {
const newCurrentTeam = await fetchMyTeams();
await fetchReceivedInvitations();
if (newCurrentTeam && !newCurrentTeam.isPersonal) {
await fetchTeamMembers(newCurrentTeam.teamId);
// Only fetch invitations if user is team leader
if (newCurrentTeam.isLeader) {
await fetchTeamInvitations(newCurrentTeam.teamId);
}
}View on GitHub (pinned to 9ef20dcab8)
Solutions
- Disable the invite button in the UI until currentTeam is non-null
- Guard the inviteUser call site with a currentTeam null check before invoking
- Ensure teams are loaded (loading === false) before rendering team management controls
- Use isTeamLeader to gate the invite UI — only team leaders can invite
Example fix
// before
const inviteUser = async (email: string) => {
if (!currentTeam) throw new Error("No current team");
await apiClient.post("/api/v1/team/invite", { ... });
};
// after (in the UI component)
const handleInvite = async (email: string) => {
if (!currentTeam || !isTeamLeader) return;
await inviteUser(email);
}; Defensive patterns
Strategy: validation
Validate before calling
// Guard the invite UI before calling inviteUser
if (!currentTeam || !isTeamLeader) {
return; // don't show invite controls
} Try / catch
try {
await inviteUser(email);
showToast('Invitation sent', 'success');
} catch (e) {
if (e instanceof Error && e.message.includes('No current team')) {
setError('Please select or create a team first.');
} else {
setError(e instanceof Error ? e.message : 'Failed to send invitation');
}
} Prevention
- Disable the invite button until currentTeam is non-null and isTeamLeader is true
- Ensure teams are fully loaded (loading === false) before rendering team management controls
- Guard every context action that depends on currentTeam with a null check in the UI layer
When it happens
Trigger: inviteUser() is called before the team context has resolved (race condition during initial load), or after a team was deleted/deselected. The inviteUser function is exposed via context and called from the team management UI.
Common situations: Team management panel rendered before fetchMyTeams() resolves; user has no teams (new account); team was just left/deleted and currentTeam was cleared; component calling inviteUser doesn't guard on currentTeam availability.
Related errors
- No team to invite to
- Member has no team to be removed from
- No team resolved yet
- error.message
- Email missing for this user. Please contact support for manu
AI-assisted analysis of Stirling-Tools/Stirling-PDF@9ef20dcab8 (2026-08-13).
Data as JSON: /api/errors/072166a6d6d5c84d.
Report an issue: GitHub.