News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Multi-user app logs other users out if one user logs out
Tags: rest api, sdk, integrations
Aug 15, 2022 at 4:01pm   •   1 replies  •  0 likes
GEQ API

I'm not sure how to start, but we have a node app that was built off the example oauth app from the dev guide. It's been built out to basically monitor the presence status of an extension, updating every 5 seconds. Multiple users should be able to login and their sessions are being stored using express-session and MySQL store.


It seemed to work fine but when testing with multiple users, if one user hits the /logout endpoint, then the other user(s) get logged out as well. I have no idea where to start with this or what could be causing it. Shouldn't each user have their own session tokens, I can see the sessions in the MySQL sessions table and it appears to create a new session for each login, but for some reason the tokens are revoked for all users when only one user hits logout.


I'm using this code for the /logout endpoint taken from the dev guide:

app.get("/logout", async function (req, res) {
    if (req.session.tokens != undefined) {
        const platform = rcsdk.platform();
        platform.auth().setData(req.session.tokens);
        if (platform.loggedIn()) {
            try {
                const resp = await platform.logout();
                console.log("logged out");
            } catch (e) {
                console.log(`/logout error:`, e.message);
            }
        }
        req.session.tokens = null;
    }
    res.redirect("/");
});

Please let me know if any more information is needed, I'm trying to figure it out and tweak things but I honestly have no idea if it's because platform.logout() will revoke all the tokens (which I think it shouldn't since each login has their own token pairs).

The app is pretty simple but it has this issue which pretty much makes it useless since all users have to relogin when one logs out.

The dev guide I followed to get the skeleton of the app:

https://developers.ringcentral.com/guide/authentication/quick-start

1 Answer
answered on Aug 16, 2022 at 6:46am  

I notice now that the sample code has some mistakes. You can fix it on your code by adding the 'await' keyword to the async function calls.

const platform = rcsdk.platform();
await platform.auth().setData(req.session.tokens);
if (await platform.loggedIn()) {
    try {
        const resp = await platform.logout();
        console.log("logged out");
    } catch (e) {
        console.log(`/logout error:`, e.message);
    }
}

For supporting multiple users read this section to set the SDK configurations.


 1
on Aug 16, 2022 at 9:32pm   •  0 likes

I'm not sure I'm understanding the linked GH readme. Do I need to create an instance of the rcsdk for EACH user that will login? There's going to be 60 or so users that will be logging into this app. Shouldn't it handle multiple users and have their session data separate? Or do I have to instantiate 60 different rcsdk instances for each user that logs in?

In a node.js app this seems really weird. Maybe I'm just not clear on what the documentation is trying to convey.


on Aug 17, 2022 at 1:30am   •  0 likes

You don't have to use multiple instance of the SDK if you don't need to.

It's all depends on your implementation. Are you sure that if one of the user does not logout, other users are using their access tokens correctly and successfully? Share some more code about how to implement the login, save the tokens and set the token every time you call an API.

on Aug 17, 2022 at 12:01pm   •  0 likes

Is it possible I can message you the code privately? There's some stuff in there I wouldn't want public.

on Aug 18, 2022 at 5:26am   •  0 likes

I am super busy right now. But if you want, you can send some code to phong.vu@ringcentral.com



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us