Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 46 additions & 27 deletions src/api/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,35 +84,54 @@ class SessionsSocket {
return this.socket.is_set();
}

private async fetchSocketToken(): Promise<string> {
const res = await fetch(`${backendApi.BACKEND_URL}/auth/socket-token/`, {
credentials: 'include'
});

if (!res.ok) {
throw new Error('Not authenticated');
}

const data = await res.json();
return data.token;
}

async connect(participantName: string): Promise<SessionsSocket> {
return new Promise((resolve, reject) => {
const query = {
...(this.sessionId ? { session_id: this.sessionId } : {}),
participant_name: participantName,
};

const newSocket = io(this.config.url, {
query,
auth: {
token: 'dummy', // TODO: Replace with actual federated authentication token
},
path: this.config.path,
secure: this.config.secure,
});

this.socket.set(newSocket);

newSocket.on('connected', data => {
this._clientId = data['client_id'];
this._sessionId = data['session_id'];
this._sessionInfo = data['session_info'];
resolve(this);
});

newSocket.on('connect_error', (err) => {
this.socket.unset();
reject(err);
});
this.fetchSocketToken()
.then(token => {
const query = {
...(this.sessionId ? { session_id: this.sessionId } : {}),
participant_name: participantName,
};

const newSocket = io(this.config.url, {
query,
auth: {
token,
},
path: this.config.path,
secure: this.config.secure,
});

this.socket.set(newSocket);

newSocket.on('connected', data => {
this._clientId = data['client_id'];
this._sessionId = data['session_id'];
this._sessionInfo = data['session_info'];
resolve(this);
});

newSocket.on('connect_error', (err) => {
this.socket.unset();
reject(err);
});
})
.catch(err => {
reject(err);
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useSearchParams } from 'react-router-dom';
import { uniqueNamesGenerator, adjectives, animals } from 'unique-names-generator';
import useSession from '../../../../hooks/useSession';
import { Participant } from '../../../../@types';
import backendApi from '../../../../api/backend';

type Props = {
isOpen: boolean,
Expand Down Expand Up @@ -125,6 +126,11 @@ const CollabModal = ({ isOpen, closeModal }: Props) => {
};

const handleCreateSession = () => {
if (!userSignedIn) {

@mariana2103 mariana2103 May 14, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The auth guard is only added to handleCreateSession, but handleStartSession also calls sessionsSocket.connect(), which now requires a valid token. An unauthenticated user joining via a shared link (?session=...) or the sessions list will hit the fetchSocketToken 401, fall into the .catch, and see a generic "Erro ao entrar na sessão" toast instead of being redirected to login.

Needs the same guard:

Suggested change
if (!userSignedIn) {
const handleStartSession = (sessionId) => {
if (!userSignedIn) {
window.location.href = backendApi.OIDC_LOGIN_URL;
return;
}

window.location.href = backendApi.OIDC_LOGIN_URL;
return;
}

sessionsSocket.sessionId = null;
sessionsSocket.connect(getName())
.then(sessionsSocket => {
Expand Down
Loading