Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/fetchers/cookie-fetchers.js
// @flow | // @flow | ||||
import { deviceTypes } from 'lib/types/device-types.js'; | |||||
import { dbQuery, SQL } from '../database/database.js'; | import { dbQuery, SQL } from '../database/database.js'; | ||||
// This function is used for invalidating native sessions so that we can trigger | // This function is used for invalidating native sessions so that we can trigger | ||||
// a log-in on the next socket connection attempt. We initially introduced this | // a log-in on the next socket connection attempt. We initially introduced this | ||||
// during the rollout of the identity service, where we needed the user's | // during the rollout of the identity service, where we needed the user's | ||||
// password on the keyserver to populate the identity service. We only | // password on the keyserver to populate the identity service. We only | ||||
// invalidate native sessions because web sessions don't cache the user's | // invalidate native sessions because web sessions don't cache the user's | ||||
// password, and we don't want any user-visible issues to result from this. | // password, and we don't want any user-visible issues to result from this. | ||||
async function fetchNativeCookieIDsForUserIDs( | async function fetchCookieIDsToInvalidateToPopulateIdentityService( | ||||
userIDs: $ReadOnlyArray<string>, | userIDs: $ReadOnlyArray<string>, | ||||
): Promise<string[]> { | ): Promise<string[]> { | ||||
// Native clients before codeVersion 193 don't provide the info necessary to | |||||
// call the identity service, so there's no point to invalidating their | |||||
// sessions. On Android, builds 193/194 have a bug that breaks log-in, so we | |||||
// don't want to invalidate their sessions. | |||||
const query = SQL` | const query = SQL` | ||||
SELECT id | SELECT id | ||||
FROM cookies | FROM cookies | ||||
WHERE platform IN (${deviceTypes}) AND user IN (${userIDs}) | WHERE user IN (${userIDs}) AND ( | ||||
(platform = 'ios' AND JSON_EXTRACT(versions, '$.codeVersion') > 192) OR | |||||
(platform = 'android' AND JSON_EXTRACT(versions, '$.codeVersion') > 194) | |||||
) | |||||
`; | `; | ||||
const [result] = await dbQuery(query); | const [result] = await dbQuery(query); | ||||
return result.map(({ id }) => id.toString()); | return result.map(({ id }) => id.toString()); | ||||
} | } | ||||
export { fetchNativeCookieIDsForUserIDs }; | export { fetchCookieIDsToInvalidateToPopulateIdentityService }; |