My network requests with the flutter SDK aren't working. I am able to login successfully to my pyth...
a
My network requests with the flutter SDK aren't working. I am able to login successfully to my python backend, but when I try to query the API with a POST, I get a 401. Here is what the debug log on the backend says:
r
hey @andrewbyrley
it seems that the access token is missing in the request. What are all the request headers?
a
r
whats the api domain that is set on the frontend's init?
a
here's the init in main:
and here's the provider code:
r
@nkshah2 can help out tomorrow.
n
Hi @andrewbyrley Can you print the value of API_DOMAIN in your dart code before you call SuperTokens init and see what the value is?
Also what platform are you running on?
a
hey @nkshah2! Here is the output of printing API_DOMAIN:
Copy code
flutter: API_DOMAIN is:
flutter: http://localhost:8000
As far as platform, I'm not 100% what you're asking, but I'm on ubuntu running supertokens_flutter (0.2.7) via VScode. Backend is supertokens_python (0.15.2)
n
I meant are you building for Flutter web, desktop or android/ios?
@andrewbyrley
a
Ultimately for mobile, but this test is running on Linux
n
Right so the SDK only support mobile for now, it doesnt work fully for Desktop or Web
Can you try running on an emulator/simulator to see if the issue persists?
a
Ah! Ok.
Yes I'll do that and report back. I won't be able to get to it until later today
n
Sounds good
a
hey @nkshah2, I'm getting the same error using an android emulator. I had to upate the API_DOMAIN from
localhost
to
10.0.2.2
.
I'm able to login and get an OK response back from the backend:
{status: OK, user: {id: fXXXX25c-XXXX-XXXX-a4b4-XXXXXXXXea84, email: this-is-the-email@gmail.com, timeJoined: 16684XXX46244}}
But calling
bool sessionExists = await SuperTokens.doesSessionExist();
after logging in returns
false
n
And youve changed it to using the IP on both your frontend and backend?
a
The backend is registering the connections as being from
localhost
, even when the flutter client is reaching out to 10.0.2.2, so I didn't change the IP on the frontend. I'll try that and report back.
n
Yep the domain needs to match for both the frontend and backend
a
@nkshah2 I'm still getting the error
om.supertokens {"t": "2023-09-25T16:33:00.401Z", "sdkVer": "0.15.2", "message": "getSession: UNAUTHORISED because accessToken in request is undefined", "file": "recipe/session/recipe_implementation.py:200"}
backend config:
n
Can you try using your machines local IP as the API domain for both the frontend and the backend?
Also inside flutter (running on Android) can you print the full response of the API that creates a session?
a
can you be more specific? Are you asking to print the response of the HTTP call?
n
The response headers specifically
a
here are the response headers:
Copy code
{
  "message": "unauthorised"
}
n
I meant the headers for the sign in response
a
apologies. here are the sign-in response headers:
n
And doesSessionExist returns false immediately after this?
a
yes
n
Hmm ill see if I can recreate this in a fresh project
a
Copy code
void sendLoginToSuperTokens(
    String email, String password, BuildContext context) async {

  if (kDebugMode) {
    print(email);
    print(password);
  }

  var response = await http.post(
    Uri.parse('${dotenv.env['API_DOMAIN']}/auth/signin'),
    headers: <String, String>{
      'rid': 'thirdpartyemailpassword',
      'Content-Type': 'application/json; charset=utf-8',
    },
    body: jsonEncode(
      <String, List<Map<String, String>>>{
        'formFields': [
          {
            'id': 'email',
            'value': email,
          },
          {
            'id': 'password',
            'value': password,
          },
        ],
      },
    ),
  );

  if (kDebugMode) {
    // print(jsonDecode(response.body)['message']);
    print(jsonDecode(response.body));
  }

  if (jsonDecode(response.body)['status'] == 'OK') {
    // Navigate to home screen
    var isLoggedIn = await SuperTokens.doesSessionExist();
    if (kDebugMode) {
      print('isLoggedIn is');
      print(isLoggedIn);
    }
    Navigator.of(context)
        .pushReplacement(MaterialPageRoute(builder: (context) => const Home()));
  } else {
    // Show error message
    ScaffoldMessenger.of(context).showSnackBar(
      const SnackBar(
        content: Text("ruh roh"),
      ),
    );
  }
}
that's the function im using, if it's helpful
n
That helps thanks! Give me a bit and ill get back
Can I see the import for
http
?
a
omg. i had the supertokens_http imported in my provider, but I was using the default http in main
i just imported the supertokens_http in main
i'm sorry for having wasted your time 🤦
n
Happens to the best of us :p Happy to help!
a
you all are amazing with customer support and helping out! I don't have a project that is making you all any money yet, but hopefully one day -- thanks again!