Skip to content

feat: Allow logout with invalid session token #1803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7360d27
Update CloudCode.js
dblythy Aug 19, 2020
1b197a5
Merge pull request #1 from dblythy/patch-1
dblythy Aug 19, 2020
ed9e32a
Update CloudCode.js
dblythy Aug 19, 2020
36af6e1
Merge branch 'master' of https://github.com/dblythy/Parse-SDK-JS
dblythy Feb 10, 2021
99da8be
Merge remote-tracking branch 'upstream/alpha'
dblythy Mar 18, 2022
cfc525d
Merge branch 'parse-community:alpha' into alpha
dblythy May 26, 2022
56b46b6
Merge remote-tracking branch 'upstream/alpha' into alpha
dblythy Jun 6, 2022
9f504a9
Merge remote-tracking branch 'upstream/alpha' into alpha
dblythy Jul 26, 2022
4d62c21
Merge remote-tracking branch 'upstream/alpha' into alpha
dblythy Sep 14, 2022
759a690
Merge remote-tracking branch 'upstream/alpha' into alpha
dblythy Nov 30, 2022
bc5eaf3
Merge remote-tracking branch 'upstream/alpha' into alpha
dblythy Jan 30, 2023
1029d8b
feat: allow logout with `clearSession` to logout with invalid session…
dblythy Mar 2, 2023
e08347c
Merge branch 'alpha' into session_logout
dblythy Mar 2, 2023
837067c
Merge branch 'alpha' into session_logout
mtrezza Jul 23, 2023
173d915
Merge branch 'alpha' into session_logout
mtrezza Sep 3, 2023
90ee8bb
Merge remote-tracking branch 'upstream/alpha' into session_logout
dplewis Apr 16, 2025
36c67ab
docs, types, coverage
dplewis Apr 16, 2025
f275357
Merge branch 'alpha' into session_logout
mtrezza Apr 19, 2025
f412d7f
Merge branch 'alpha' into session_logout
mtrezza May 6, 2025
4e5f6a4
Merge branch 'alpha' into session_logout
mtrezza Jun 3, 2025
ccbe731
Merge branch 'alpha' into session_logout
mtrezza Jun 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: allow logout with clearSession to logout with invalid session…
… token
  • Loading branch information
dblythy committed Mar 2, 2023
commit 1029d8b2d1a91fc83953b025cfbb487acc0d3f50
16 changes: 12 additions & 4 deletions src/ParseUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1134,18 +1134,26 @@ const DefaultController = {

logOut(options: RequestOptions): Promise<ParseUser> {
const RESTController = CoreManager.getRESTController();
const promiseCatch = e => {
if (e.code === ParseError.INVALID_SESSION_TOKEN && options.clearSession) {
return;
}
throw e;
};
if (options.sessionToken) {
return RESTController.request('POST', 'logout', {}, options);
return RESTController.request('POST', 'logout', {}, options).catch(promiseCatch);
}
return DefaultController.currentUserAsync().then(currentUser => {
const path = Storage.generatePath(CURRENT_USER_KEY);
let promise = Storage.removeItemAsync(path);
if (currentUser !== null) {
const currentSession = currentUser.getSessionToken();
if (currentSession && isRevocableSession(currentSession)) {
promise = promise.then(() => {
return RESTController.request('POST', 'logout', {}, { sessionToken: currentSession });
});
promise = promise
.then(() => {
return RESTController.request('POST', 'logout', {}, { sessionToken: currentSession });
})
.catch(promiseCatch);
}
currentUser._logOutWithAll();
currentUser._finishFetch({ sessionToken: undefined });
Expand Down
34 changes: 34 additions & 0 deletions src/__tests__/ParseUser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,40 @@ describe('ParseUser', () => {
});
});

it('can logout user with clear session', async () => {
ParseUser.disableUnsafeCurrentUser();
ParseUser._clearCache();
Storage._clear();
const RESTController = {
request() {
const error = new ParseError(ParseError.INVALID_SESSION_TOKEN, 'Invalid session token.');
return Promise.reject(error);
},
ajax() {},
};
jest.spyOn(RESTController, 'request');
CoreManager.setRESTController(RESTController);

await ParseUser.logOut({ clearSession: true });
});

it('can logout user with clear session and session token', async () => {
ParseUser.disableUnsafeCurrentUser();
ParseUser._clearCache();
Storage._clear();
const RESTController = {
request() {
const error = new ParseError(ParseError.INVALID_SESSION_TOKEN, 'Invalid session token.');
return Promise.reject(error);
},
ajax() {},
};
jest.spyOn(RESTController, 'request');
CoreManager.setRESTController(RESTController);

await ParseUser.logOut({ sessionToken: '1234', clearSession: true });
});

it('can retreive a user with sessionToken (me)', async () => {
ParseUser.disableUnsafeCurrentUser();
ParseUser._clearCache();
Expand Down