Skip to content

Commit 36c67ab

Browse files
committed
docs, types, coverage
1 parent 90ee8bb commit 36c67ab

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

src/CoreManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export interface UserController {
197197
loginAs: (user: ParseUser, userId: string) => Promise<ParseUser>;
198198
become: (user: ParseUser, options?: RequestOptions) => Promise<ParseUser>;
199199
hydrate: (user: ParseUser, userJSON: AttributeMap) => Promise<ParseUser>;
200-
logOut: (options?: RequestOptions) => Promise<void>;
200+
logOut: (options?: RequestOptions & { clearSession?: boolean }) => Promise<void>;
201201
me: (user: ParseUser, options?: RequestOptions) => Promise<ParseUser>;
202202
requestPasswordReset: (email: string, options?: RequestOptions) => Promise<void>;
203203
updateUserOnDisk: (user: ParseUser) => Promise<ParseUser>;

src/ParseUser.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,11 +812,13 @@ class ParseUser<T extends Attributes = Attributes> extends ParseObject<T> {
812812
* <code>current</code> will return <code>null</code>.
813813
*
814814
* @param {object} options
815+
* @param {boolean} [options.clearSession] If true, the session token will be
816+
* removed from the user object when the session token is invalid.
815817
* @static
816818
* @returns {Promise} A promise that is resolved when the session is
817819
* destroyed on the server.
818820
*/
819-
static logOut(options?: RequestOptions): Promise<void> {
821+
static logOut(options?: RequestOptions & { clearSession?: boolean }): Promise<void> {
820822
const controller = CoreManager.getUserController();
821823
return controller.logOut(options);
822824
}
@@ -1205,10 +1207,11 @@ const DefaultController = {
12051207
});
12061208
},
12071209

1208-
logOut(options?: RequestOptions): Promise<void> {
1210+
logOut(options?: RequestOptions & { clearSession?: boolean }): Promise<void> {
12091211
const RESTController = CoreManager.getRESTController();
12101212
const promiseCatch = e => {
1211-
if (e.code === ParseError.INVALID_SESSION_TOKEN && options.clearSession) {
1213+
console.log(e, options);
1214+
if (e.code === ParseError.INVALID_SESSION_TOKEN && options?.clearSession) {
12121215
return;
12131216
}
12141217
throw e;

src/__tests__/ParseUser-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,28 @@ describe('ParseUser', () => {
10761076
await ParseUser.logOut({ sessionToken: '1234', clearSession: true });
10771077
});
10781078

1079+
it('cannot logout user with invalid session', async () => {
1080+
expect.assertions(2);
1081+
ParseUser.disableUnsafeCurrentUser();
1082+
ParseUser._clearCache();
1083+
Storage._clear();
1084+
const RESTController = {
1085+
request() {
1086+
const error = new ParseError(ParseError.INVALID_SESSION_TOKEN, 'Invalid session token.');
1087+
return Promise.reject(error);
1088+
},
1089+
ajax() {},
1090+
};
1091+
jest.spyOn(RESTController, 'request');
1092+
CoreManager.setRESTController(RESTController);
1093+
try {
1094+
await ParseUser.logOut({ sessionToken: '1234', clearSession: false });
1095+
} catch (e) {
1096+
expect(e.code).toBe(ParseError.INVALID_SESSION_TOKEN);
1097+
expect(e.message).toBe('Invalid session token.');
1098+
}
1099+
});
1100+
10791101
it('can retreive a user with sessionToken (me)', async () => {
10801102
ParseUser.disableUnsafeCurrentUser();
10811103
ParseUser._clearCache();

types/CoreManager.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ export interface UserController {
178178
loginAs: (user: ParseUser, userId: string) => Promise<ParseUser>;
179179
become: (user: ParseUser, options?: RequestOptions) => Promise<ParseUser>;
180180
hydrate: (user: ParseUser, userJSON: AttributeMap) => Promise<ParseUser>;
181-
logOut: (options?: RequestOptions) => Promise<void>;
181+
logOut: (options?: RequestOptions & {
182+
clearSession?: boolean;
183+
}) => Promise<void>;
182184
me: (user: ParseUser, options?: RequestOptions) => Promise<ParseUser>;
183185
requestPasswordReset: (email: string, options?: RequestOptions) => Promise<void>;
184186
updateUserOnDisk: (user: ParseUser) => Promise<ParseUser>;

types/ParseUser.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,15 @@ declare class ParseUser<T extends Attributes = Attributes> extends ParseObject<T
392392
* <code>current</code> will return <code>null</code>.
393393
*
394394
* @param {object} options
395+
* @param {boolean} [options.clearSession] If true, the session token will be
396+
* removed from the user object when the session token is invalid.
395397
* @static
396398
* @returns {Promise} A promise that is resolved when the session is
397399
* destroyed on the server.
398400
*/
399-
static logOut(options?: RequestOptions): Promise<void>;
401+
static logOut(options?: RequestOptions & {
402+
clearSession?: boolean;
403+
}): Promise<void>;
400404
/**
401405
* Requests a password reset email to be sent to the specified email address
402406
* associated with the user account. This email allows the user to securely

0 commit comments

Comments
 (0)