How can I pass the sessionToken to the wix website?

Hi, everyone !

Is it possible to login automatically with some info(for example, cookie or token added in Headers)?
I put a website page in my mobile app( through webview method). After user login on the app, is it possible for No twice login on the website (as showed through webview method)?

So here is what I found may be useful to realise it.

wixUsers.applySessionToken(sessionToken);

I can use a request in http-funtions.js to get the seesionToken.
But this token is not in the website but returned in the mobile app. How can I pass this sessionToken to the wix website?
Thanks in advance.

Hi :raised_hand_with_fingers_splayed:

You can pass the session token as a location parameter with wixLocation API when you open the website in the webview.

For example:

  1. When the user login successfully on the app, post the email of that user to a pre-configured endpoint, and let the endpoint generate a session token and return it to your app.

  2. When your app gets the session token, add it to your site URL location parameters like this www.domain.com/app-login? loginToken ={token}

  3. On that page - a page only to login via the app - create a function that will try to login the user using the loginToken parameter in the URL, then, on success, redirect the user to the home page, and on failure, redirect the user to an error page.

You can make the process a lot more complicated by adding a lot of features and fallbacks, I apologize for not providing any code since it’ll be too long, but my assumption is that you’re more than able to acheive the above, you just needed a little help to light the way.

Let me know how it goes.
Good luck :wink:

Hi, Ahmad! Thanks for your detailed reply. I appreciate it very much, truly.
But how can I realise the step 3? I couldn’t find a feasible function in Corvid doc to do that - login the user using the email and its loginToken .

@122809512 You can use the generateSessinoToken( ) function on the server side (backend ) to generate the token by passing the user email to it as a parameter.

return wixUsersBackend.generateSessionToken(email).then(sessionToken => {
    return sessionToken 
})

The code above is needed on step 1, not 3, the above sessionToken should be returned to your app.

Then on the app-login page, use applySessionToken( ) function on the client side (frontend).

wixUsers.applySessionToken(sessionToken);
// On success, the user will be logged in.

@ahmadnasriya Thanks, Ahmad! it works finally. that’s very nice of you!

@122809512 You’re welcome :wink: Glad that it worked!