feathers icon indicating copy to clipboard operation
feathers copied to clipboard

connection user is undefined ?

Open joacub opened this issue 4 years ago • 2 comments

app.on('login', (_payload, { connection }) => {
    // connection can be undefined if there is no
    // real-time connection, e.g. when logging in via REST
    if (connection) {
      // Obtain the logged in user from the connection
      const { user } = connection;

user is always undefined, is never attached anymore ? or I should do this by my self ?

here is when is suppose to be added the user to the connection, but I don't see that.

async handleConnection (event: ConnectionEvent, connection: any, authResult?: AuthenticationResult): Promise<void> {
    const isValidLogout = event === 'logout' && connection.authentication && authResult &&
      connection.authentication.accessToken === authResult.accessToken;

    const { accessToken } = authResult || {};

    if (accessToken && event === 'login') {
      debug('Adding authentication information to connection');
      const { exp } = await this.authentication.verifyAccessToken(accessToken);
      // The time (in ms) until the token expires
      const duration = (exp * 1000) - Date.now();
      // This may have to be a `logout` event but right now we don't want
      // the whole context object lingering around until the timer is gone
      const timer = lt.setTimeout(() => this.app.emit('disconnect', connection), duration);

      debug(`Registering connection expiration timer for ${duration}ms`);
      lt.clearTimeout(this.expirationTimers.get(connection));
      this.expirationTimers.set(connection, timer);

      debug('Adding authentication information to connection');
      connection.authentication = {
        strategy: this.name,
        accessToken
      };
    } else if (event === 'disconnect' || isValidLogout) {
      debug('Removing authentication information and expiration timer from connection');

      const { entity } = this.configuration;

      delete connection[entity];
      delete connection.authentication;

      lt.clearTimeout(this.expirationTimers.get(connection));
      this.expirationTimers.delete(connection);
    }
  }

joacub avatar Sep 14 '21 06:09 joacub

I saw the difference with others version is the next function in the hooks, I don't know but the events firing first than the connection hooks

joacub avatar Sep 14 '21 11:09 joacub

+1 any other updates on this issue?

jonasostrom avatar Dec 03 '21 09:12 jonasostrom