onDisconnect: How to track user? #95
Comments
The same |
Yeah I noticed that, I was wondering if I could stick some data in there, was thinking it would probably be just easiest to do it that way. Is there a reason I'd use one or the other? Thanks so much! |
Using an external Map() would ensure that you don't accidentally overwrite any state on the
|
To add to this, I think it would be valuable if the context properties which are returned from |
Here's a relevant thread on Apollo's Spectrum that has a code snippet on accessing |
Here's a simple version of what's shown in @mwood23's link. subscriptions: {
onConnect: connectionParams => {
const apiKey = connectionParams['x-api-key'];
ensureApiKey(apiKey);
const user = Users.findOne({apiKey}) || {name: 'guest'};
log.info(`<ws> ${user.name} connected.`);
return {
user
};
},
onDisconnect: async (_, context) => {
const initialContext = await context.initPromise;
log.info(`<ws> ${initialContext.user.name} disconnected.`);
}
} |
I'd like to figure out how to run some commands for a specific user when they disconnect. Is there something like a state that is stored to be able to reference within the onDisconnect hook?
The text was updated successfully, but these errors were encountered: