Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Cannot use multiple instances of R6API #71

Open
BadCoder1337 opened this issue Sep 1, 2021 · 3 comments
Open

Cannot use multiple instances of R6API #71

BadCoder1337 opened this issue Sep 1, 2021 · 3 comments
Labels
type: feature New feature or request

Comments

@BadCoder1337
Copy link
Contributor

I need to create a different session with non-default Ubi-AppId to interact with another domain of endpoints.
Example code:

const friendsApi = new R6API(credentials)
const chatApi = new R6API({ ...credentials, ubiAppId: OVERLAY_APP_ID })

const friendsApiAuth = await friendsApi.getAuth()
const chatApiAuth = await chatApi.getAuth()
console.log(friendsApiAuth, chatApiAuth)

But because of global variables in auth.ts and other places I cannot construct 2nd R6API instance. getAuth from both instances gives the same object which is impossible since session endpoint is non-idempotent.

@danielwerg
Copy link
Owner

You can call setAuthFileName method before you need to change ubi app id, it's non-ideal solution but a workaround.

const friendsApi = new R6API(credentials)
- const chatApi = new R6API({ ...credentials, ubiAppId: OVERLAY_APP_ID })
+ const chatApi = new R6API(credentials)

+ const defaultAppId = '3587dcbb-7f81-457c-9781-0e3f29f6f56a';
+ const altAppId = '83564d31-7cd7-4bc0-a763-6524e78d1a7f';

+ friendsApi.setAuthFileName(`r6api.js-auth-${defaultAppId}`);
const friendsApiAuth = await friendsApi.getAuth()
+ chatApi.setAuthFileName(`r6api.js-auth-${altAppId}`);
const chatApiAuth = await chatApi.getAuth()
console.log(friendsApiAuth, chatApiAuth)

@danielwerg
Copy link
Owner

@BadCoder1337 did example above resolve your issue?

@BadCoder1337
Copy link
Contributor Author

I split code into separate workers. It's easier for me than creating and loading JSON. But the issue is still relevant as a refactor goal.

@danielwerg danielwerg added the type: feature New feature or request label Jun 27, 2022
@danielwerg danielwerg mentioned this issue Dec 27, 2022
25 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants