https://supertokens.com/ logo
d

dhatGuy

06/11/2022, 1:17 PM
Copy code
async function doesSessionExist() {
    if (await SuperTokens.doesSessionExist()) {
      // user is logged in
      console.log("there is a session");
    } else {
      // user has not logged in yet
    }
  }
this returns error in react native
r

rp

06/11/2022, 1:30 PM
hey @dhatGuy how are you importing supertokens?
d

dhatGuy

06/11/2022, 1:30 PM
import SuperTokens from 'supertokens-react-native';
r

rp

06/11/2022, 1:31 PM
have you called supertokens.init?
perhaps @nkshah2 can help here too
n

nkshah2

06/11/2022, 1:32 PM
Hey @dhatGuy can you post the code for where you are calling SuperTokens.init?
d

dhatGuy

06/11/2022, 1:33 PM
Copy code
import SuperTokens from "supertokens-react-native";

const apiDomain = "http://192.168.43.75:7000"; // TODO: change url to your own IP address

SuperTokens.init({
  apiDomain,
  apiBasePath: "/api/auth",
});
am I meant to export it?
n

nkshah2

06/11/2022, 1:34 PM
Nope, as long as that piece of code is running before you access any of the functions it should work
Can you add a log above the init call and another one before using doesSessionExist and see what order the code is running in?
d

dhatGuy

06/11/2022, 1:43 PM
I think I've found the error. I should have the code above in App.js
n

nkshah2

06/11/2022, 1:44 PM
Yeah it should be in a place that always runs before the rest of your app
Either App.js or index.js works
index for the app I mean
d

dhatGuy

06/11/2022, 1:46 PM
im getting an error, "Please, provide a valid domain name"
n

nkshah2

06/11/2022, 1:53 PM
Strange, the value you use does work for me
d

dhatGuy

06/11/2022, 1:58 PM
it works now. I had to restart the server
thanks
n

nkshah2

06/11/2022, 2:11 PM
Ah, happy to help
d

dhatGuy

06/11/2022, 2:43 PM
please, it keeps saying I don't have any session
even after logging in
r

rp

06/11/2022, 2:59 PM
@dhatGuy what's the backend config?
d

dhatGuy

06/11/2022, 3:14 PM
it's a bit large coz I have custom config
r

rp

06/11/2022, 3:15 PM
just the appInfo part and session.init part
d

dhatGuy

06/11/2022, 3:16 PM
Copy code
appInfo: {
    appName: "nsm",
    apiDomain: "http://localhost:7000",
    websiteDomain: "http://localhost:3000",
    apiBasePath: "/api/auth",
    websiteBasePath: "/api/auth",
  }
r

rp

06/11/2022, 3:16 PM
you need to make sure that you use the same apiDomain value on frontend and backend
d

dhatGuy

06/11/2022, 3:16 PM
Session.init({})
in RN, I cant use localhost
i have to use the network ip address
r

rp

06/11/2022, 3:17 PM
so you need to give that to the apiDOmain on the backend as well.
ok i think the issue could be something else
are you using axios?
if yes, you need to make sure that you had added the supertokens interceptor to the axios instance
d

dhatGuy

06/11/2022, 3:31 PM
I have. The issue was me using a wrong ip address. im receiving a response that there is session now
thank you
r

rp

06/11/2022, 3:33 PM
Ok great!
2 Views