Skip to content

Commit

Permalink
Merge pull request #198 from getbraincloud/BCLOUD-6696_Add-Logout-To-…
Browse files Browse the repository at this point in the history
…Wrapper

added logout function to wrapper and created test
  • Loading branch information
bitheadCody authored Dec 22, 2023
2 parents 7d2da02 + fa58413 commit e4df21e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/brainCloudWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ function BrainCloudWrapper(wrapperName) {
*
*/
bcw.authenticateAnonymous = function(responseHandler) {

bcw._initializeIdentity(true);

bcw.brainCloudClient.authentication.authenticateAnonymous(
Expand Down Expand Up @@ -1263,6 +1262,19 @@ function BrainCloudWrapper(wrapperName) {
}
});
}

/**
* Logs user out of server.
* @param {boolean} forgetUser Determines whether the stored profile ID should be reset or not
* @param {*} responseHandler Function to invoke when request is processed
*/
bcw.logout = function(forgetUser, responseHandler){
if(forgetUser){
bcw.resetStoredProfileId()
}

bcw.brainCloudClient.playerState.logout(responseHandler)
}
}

/**
Expand Down
26 changes: 26 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5782,6 +5782,32 @@ async function testWrapper()
});
});
});

function testLogout(forgetUser, logoutCallback){
bc.resetStoredProfileId()

bc.authenticateAnonymous(function() {
bc.logout(forgetUser, logoutCallback)
});
}

await asyncTest("logout() remember user", 2, function () {
testLogout(false, function(result) {
equal(result.status, 200, JSON.stringify(result));

equal(bc.getStoredProfileId() == "", false, "Profile ID was NOT reset: " + bc.getStoredProfileId())
resolve_test()
})
})

await asyncTest("logout() forget user", 2, function () {
testLogout(true, function(result) {
equal(result.status, 200, JSON.stringify(result));

equal(bc.getStoredProfileId() == "", true, "Profile ID WAS reset: " + bc.getStoredProfileId())
resolve_test()
})
})
}

////////////////////////////////////////
Expand Down

0 comments on commit e4df21e

Please sign in to comment.