I’m trying to implement regular Internet Identity login with @dfinity/auth-client in React Native. However, since React Native lacks support for localStorage or IndexedDB like web browsers, I’m encountering some confusion regarding the implementation.
I’m aware that I can use AsyncStorage in React Native to achieve similar results as browser localStorage, but I’m still unsure about how to integrate a custom storage solution into the auth-client.
Any pointers or guidance on how to proceed would be greatly appreciated.
I’m not sure if there’s any out of the box solutions for React Native, but you can easily provide a wrapper for AsyncStorage by implementing the AuthClientStorage interface and giving it to your AuthClient when you create it: https://agent-js.icp.xyz/auth-client/index.html#storage-and-key-management
Assuming that you can provide a custom AuthClientStorage with the AsyncStorage, how are you planning to successfully use the AuthClient.login function?
As also stated in the function’s docs:
Opens up a new window to authenticate with Internet Identity
it will attempt to open a new browser window. However, React Native doesn’t support opening browser windows out of the box, you need external packages like WebBrowser.
I was able to create the wrapper now and I’m opening the web browser window at AuthClient.login but after authenticating the auth client does not get the identity. I’m looking at @kpeacock example below.
Correction: I was able to initialized the auth client with a custom storage wrapper and open a web browser window on a button click but it is not in the AuthClient.login context. I’m digging into @kpeacockmvp repo to see if I can find a viable solution for delegation because it looks to me that you really can’t use AuthClient.login with react native unless you create a custom solution.
Yeah, you definitely need to open a web page and proceed from the browser. The protocol won’t let you use auth-client directly in the React Native app.
@kpeacock, thank you very much for the explanation.
I’ll keep an eye out for that release. If you get the chance, please tag me in the post when you do the release.
One more question: Do you think it’s possible to write the authentication client in a React Native style, incorporating its own async storage, event handler, etc.? I might take a stab at it