1

For my React Native app I am using Parse JS SDK and hosted Parse Server on Back4app. When I try to register a new user, the user is not authenticated because the response does not return a sessionToken.

However, once the user is in the db and signs in a sessionToken is returned and the user is authenticated successfully.

Request

The request is the same for sign in/up.

await Parse.User.logInWith('google', {
  // auth data received from @react-native-community/google-signin
  authData: {
    id,
    id_token: token
  }
})

Response on initial Sign Up

The response is supposed to return a sessionToken which is missing. So the user is not authenticated and modifications on the user object are not possible.

{
  "authData": {...}, 
  "createdAt": "...", 
  "objectId": "...", 
  "updatedAt": "...", 
  "username": "..."
}

Response on sign in after user was created

{
  "ACL": {...}, 
  "authData": {...}, 
  "createdAt": "...", 
  "objectId": "...", 
  "sessionToken": "...", 
  "updatedAt": "...", 
  "username": "..."
}

I don't use any cloud code. Just a simple auth flow with Google oAuth.

Any help is highly appreciated.

Edit: same issue for 'sign in with Apple'

Pawel
  • 1,560
  • 1
  • 10
  • 11

2 Answers2

1

As far as I know, according to the Official Documentation, Parse will respond 200 (HTTP OK) and include the Session Token only when it verifies the user is already associated with the OAuth authentication data. So, again, as far as I know, the very first request when you create the user, will not contain the sessionToken.

Alexander
  • 27
  • 2
  • 1
    Well, that's what I was thinking first as well. But the docs clearly say: *If the user has never been linked with this account, you will instead receive a status code of 201 Created, indicating that a new user was created:* ... *The body of the response will contain the objectId, createdAt, sessionToken, and an automatically-generated unique username* – Pawel May 26 '20 at 15:16
  • Got that but in that case, you are Linking your OAuth user to an existing (or created at runtime) Parse User, as the code states: const user = new Parse.User(); await user.linkWith('providerName', { authData: myAuthData }); Perhaps if you use linkWith instead? – Alexander May 26 '20 at 17:22
0

Take a look to this tutorial https://www.thinkertwin.com/how-to-setup-google-oauth2-login-with-parse-server-in-react/ Here there is an explanation on how to setup your Cloud Code. It's for React, but with small adjustments it will work for React Native. You also need Cloud Code as you need to store your Client ID and Secret. You don't want to have those on your public application

gutaku
  • 11
  • 1