I’m having a similar issue. I’m in the process of moving from Parse to Coronium. I’m making progress, but having an issue with a user logging in.
I can create the user just fine and then login immediately with the register code below:
[lua]local function onCreateUser(event)
if event.error then
print(“Error creating the user”)
local function onComplete2( event )
if “clicked” == event.action then
local i = event.index
if 1 == i then
– Do nothing
elseif 2 == i then
if username then
username:removeSelf();username=nil
end
if password then
password:removeSelf();password=nil
end
if name then
name:removeSelf();name=nil
end
if email then
email:removeSelf();email=nil
end
composer.gotoScene( “login”, “slideUp”, 500 )
end
end
end
local alert = native.showAlert( “Sorry”, “An error occurred, please try again.”, { “Try Again”, “Cancel” }, onComplete2 )
else
print(“User was created successfully”)
local function onSuccess(event)
if “clicked” == event.action then
if 1 == event.index then
local function onLoginUser( event )
globals.sessionToken = event.result.sessionToken
globals.userId = event.result.objectId
print("objectId is… "…globals.userId) --results in error saying nil value
end
coronium:loginUser( globals.email, globals.password , onLoginUser )
if username then
username:removeSelf();username=nil
end
if password then
password:removeSelf();password=nil
end
if name then
name:removeSelf();name=nil
end
if email then
email:removeSelf();email=nil
end
composer.gotoScene( “menu”, “fade”, 1400 ) --go straight into the app
elseif 2 == event.index then
local function onLoginUser( event )
globals.sessionToken = event.result.sessionToken
globals.userId = event.result.objectId
end
coronium:loginUser( globals.email, globals.password, onLoginUser )
if username then
username:removeSelf();username=nil
end
if password then
password:removeSelf();password=nil
end
if name then
name:removeSelf();name=nil
end
if email then
email:removeSelf();email=nil
end
composer.gotoScene( “login”, “slideUp”, 500 )
end
end
end
local successalert = native.showAlert(“Account created successfully.”, “Would you like to login now?”, {‘Yes’, ‘No’}, onSuccess)
end
end
local userData = {
[“username”] = globals.username,
[“password”] = globals.password,
[“email”] = globals.email,
[“name”] = globals.name,
}
coronium:registerUser( userData, onCreateUser )[/lua]
The register code above works fine, and the embedded login code above gets the user into their data appropriately; but event.result is not returning an objectId. The problem doesn’t arise, though, until the user logs out and then another user tries to login with an existing account using the code below:
[lua]local function onLoginUser( event )
if not event.error then
globals.sessionToken = event.result.sessionToken
globals.userId = event.result.objectId
print("userid1 "…event.result.objectId) --results in error saying nil value
print("sessionToken "…event.result.sessionToken)
coronium:setSessionToken( globals.sessionToken )
local function callback(event)
print("userid2 "…event.result.objectId) --Gets an objectId, but it’s the last user logged in, not the current user logging in
globals.name = event.result.name
globals.email = event.result.email
print("name "…globals.name)
print("email "…globals.email)
composer.gotoScene( “menu”, “fade”, 400 )
end
coronium:getMe( callback )
else
local function onComplete(event)
composer.gotoScene( “login”, “fade”, 400 )
end
local alert = native.showAlert( “Error”, event.error, { “OK” }, onComplete )
end
end
coronium:loginUser( globals.email, globals.password, onLoginUser )[/lua]
What seems to be happening is: even though the newly logging in user is logging in with their credentials, it logs in the user that was previously logged in. I’m sure it’s a problem with the flow of my code, but I don’t understand Coronium well enough yet to understand why.
With Parse, when a user logged in, event.result provided a sessionToken and an objectId. However, in Coronium, I’m only receiving a sessionToken and objectId returns nil as noted in the print statement comments. However, when I run getMe(), I can get an objectId returned, but in the case above, it returns the objectId for the previously logged in user.
I truly appreciate any help anyone can provide.