Open WebView with localstorage set

#1

Hi,

We use Meteor login system. We link to our website from the app for some functionality, but when the user goes to this webview he has to log in again. This is quite a hassle for the user.

What we’d like to do instead is auto log him in. Meteor uses the browser’s local storage to do the login. If we can set the localstorage from the app when opening the webview he’ll be autologged in. I’m not sure this possible to do, but if it is I would love to know how.

If there’s another way to communicate with the webview that’s opened that would also be great.

One solution I can think of is sticking the login token in the url for the user and then place that into localstorage when the page loads although I’m not sure if that’s a security best practice to have the login token in the url.

Any help would be appreciated here.

0 Likes

#2

do you use the WebView component or the WebBrowser component?

1 Like

#3

WebBrowser, but happy to switch.

0 Likes

#4

Ah I see it’s very doable with WebView. Is that what we should use?

Would you recommend using injectJavaScript?

0 Likes

#5

are you testing this with ios11 or some other os? on ios11 to maintain the session you should use WebBrowser.openAuthSessionAsynchttps://docs.expo.io/versions/latest/sdk/webbrowser.html#expowebbrowseropenauthsessionasyncurl-redirecturl

0 Likes

#6

I don’t think this is what we’re looking for. I want to send a user to our
actual site to do things. He’s already logged into the app. I just don’t
want him to login again which is what is currently happening.

0 Likes

#7

Can you answer the question about the OS though? It is relevant

0 Likes

#8

another solution would be to just pass some token through the url, and have some code on your web side that initializes state based off of that

0 Likes

#9

It would be for all popular os versions. Android and iOS

0 Likes

#10

i ask because SFSafariViewController doesn’t maintain cookies by default on ios11+. anyhow i think the solution i suggested of injecting data in url should do the trick just fine

1 Like

#11

I have a similar use case & am looking into using WebView for this since it allows me to manipulate cookies. However I like using WebBrowser & would love to see this added as a feature. (Having the ability to manipulate cookies)

0 Likes

#12

Could you please add this to our canny: https://expo.canny.io/feature-requests it would be super helpful as we work on adding features! :blue_heart::blue_heart:

1 Like