Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with React Native #11

Closed
kiwicopple opened this issue Oct 2, 2020 · 13 comments · Fixed by #21
Closed

Not working with React Native #11

kiwicopple opened this issue Oct 2, 2020 · 13 comments · Fixed by #21

Comments

@kiwicopple
Copy link
Member

This is a Hacktoberfest task!
You can read more about Hacktoberfest on our blog and see all tasks on our Hacktoberfest Project Board.

Summary

This library isn't working with React native because it tries to access localstorage.

Details

In ReactNative, there is no localstorage, it is instead AsyncStorage. We need to rewrite any calls to localstorage to guard against this. It might be better to split out all storage calls to a helper file so that we can extend it in the future.

@kiwicopple
Copy link
Member Author

@izqalan
Copy link
Contributor

izqalan commented Oct 11, 2020

I got it to work on react-native app (#14 ) but only auth.signIn doesn't seem to work as expected on react-native app.

after digging through the code it seems like api.signInWithEmail results retruns 400 Could not read password grant params: EOF on React-Native app. It work fine on postman and on example app.

my Implementation. (the same as in /example/src/app.js)
https://i.imgur.com/J0bfbEP.png

@kiwicopple
Copy link
Member Author

Hey @izqalan I merged your changes as they are a great start. I'll leave this open until we have a chance to fix the bug on api.signInWithEmail, which I will need some time to research

@kiwicopple
Copy link
Member Author

Hey @izqalan - can you please describe how you used AsyncStorage in your PR #14?

I've created a PR with an example here #21 but it doesn't look like AsyncStorage matches the interface:

image

Did you add a full wrapper around AsyncStorage to make it compatible?

@izqalan
Copy link
Contributor

izqalan commented Nov 5, 2020

Hey @kiwicopple

hmm that's strange.
I just import AsyncStorage from @react-native-community/async-storage and specify it on localStorage option.
This is how I initialize GoTrueClient class previously on my React Native app.
code
Also, it might be worth mentioning I'm using JavaScript for the app.

@kiwicopple
Copy link
Member Author

Hey @izqalan I mentioned you here, but I thought I'd drop a notification in this thread too since you're subscribed.

Do you have any public code for your RN app?

@ghost
Copy link

ghost commented Nov 26, 2020

@kiwicopple I've tried looking into this, but it appears your problem was fixed already with #24.

The example in your PR builds fine now.

@kiwicopple
Copy link
Member Author

thanks for testing @tjg1 - I saw your comment in the PR 🙏

Could I get a small favour, could you confirm the PR in our main repo works for you? supabase/supabase#315

If it is, can you let me know if you're on Android or iOS? (I only have iOS and I'm still getting the error: Could not read password grant params: EOF. Looks like a server error, but the code works when I run it in a browser.

@ghost
Copy link

ghost commented Nov 26, 2020

hi @kiwicopple,

I have just tried this out. Indeed that error gets returned by the server. It works in a browser and in React Native with a debugger attached. But it seems that while debugging, the RN code is actually running in a web worker in my browser.

I will dig deeper into this. I have a jailbroken iOS device setup with https://github.com/nabla-c0d3/ssl-kill-switch2, so I can get the actual HTTP request made by RN and compare it to the one made by the browser.

@ghost
Copy link

ghost commented Nov 26, 2020

I've done that and reproduced it with cURL.

React Native on iOS sends Content-Type: application/x-www-form-urlencoded even though the body of the request is UTF-8 JSON. Your server gets confused and returns 400 {"code":400,"msg":"Could not read password grant params: EOF"}.

Changing the header to Content-Type: text/plain, the same request succeeds.

There is still a type warning for AsyncStorageStatic, so it may need a wrapper.

@github-actions
Copy link
Contributor

🎉 This issue has been resolved in version 1.7.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@irfaan
Copy link

irfaan commented Jul 2, 2021

UPDATE: For anyone looking, this is what worked for me:

  1. Include react-native-url-polyfill ([0.59.x] URLSearchParams 'Error: not implemented' facebook/react-native#23922 (comment))
  2. Include + pod-install: react-native-async-storage (Supabase Hiccups on Mobile (React-Native) supabase#1293 (comment))

Hi! This issue persists on the latest version of supabase-js (^1.17.0):

undefined is not an object (evaluating 'this.localStorage.getItem')

react-native: 17.0.1
Supabase-js: 1.17.0

Happens with and without react-native-url-polyfill v. 1.3.0 (see facebook/react-native#23922 (comment))

@m0a
Copy link

m0a commented Feb 6, 2022

it's work!

react-native: 0.64.23,
@react-native-async-storage/async-storage: 1.15.17
@supabase/supabase-js: 1.30.0

import { createClient } from '@supabase/supabase-js'
import AsyncStorage from '@react-native-async-storage/async-storage';

const supabaseUrl = "xxxxx"
const supabaseAnonKey = 'xxx'

export const supabase = createClient(supabaseUrl, supabaseAnonKey, {localStorage: AsyncStorage})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants