[FIX] Google OAuth triggering cookies logic (#3244)

* Remove checkCookiesAndLogout

* Add loginEmailPassword to loginOAuthOrSso

* Add isFromWebView field

* Fix migrations

* Minor tweak

* Fix OAuth for other services

* Fix migrations

* Stop persisting loginEmailPassword

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Gerzon Z 2021-07-05 14:21:15 -04:00 committed by GitHub
parent 300c1f96f0
commit f42c9149fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 32 additions and 22 deletions

View File

@ -1,10 +1,11 @@
import * as types from './actionsTypes'; import * as types from './actionsTypes';
export function loginRequest(credentials, logoutOnError) { export function loginRequest(credentials, logoutOnError, isFromWebView) {
return { return {
type: types.LOGIN.REQUEST, type: types.LOGIN.REQUEST,
credentials, credentials,
logoutOnError logoutOnError,
isFromWebView
}; };
} }

View File

@ -22,7 +22,7 @@ export default class User extends Model {
@field('avatar_etag') avatarETag; @field('avatar_etag') avatarETag;
@field('login_email_password') loginEmailPassword;
@field('show_message_in_main_thread') showMessageInMainThread; @field('show_message_in_main_thread') showMessageInMainThread;
@field('is_from_webview') isFromWebView;
} }

View File

@ -95,6 +95,16 @@ export default schemaMigrations({
] ]
}) })
] ]
}, {
toVersion: 11,
steps: [
addColumns({
table: 'users',
columns: [
{ name: 'is_from_webview', type: 'boolean', isOptional: true }
]
})
]
} }
] ]
}); });

View File

@ -1,7 +1,7 @@
import { appSchema, tableSchema } from '@nozbe/watermelondb'; import { appSchema, tableSchema } from '@nozbe/watermelondb';
export default appSchema({ export default appSchema({
version: 10, version: 11,
tables: [ tables: [
tableSchema({ tableSchema({
name: 'users', name: 'users',
@ -15,7 +15,8 @@ export default appSchema({
{ name: 'roles', type: 'string', isOptional: true }, { name: 'roles', type: 'string', isOptional: true },
{ name: 'login_email_password', type: 'boolean', isOptional: true }, { name: 'login_email_password', type: 'boolean', isOptional: true },
{ name: 'show_message_in_main_thread', type: 'boolean', isOptional: true }, { name: 'show_message_in_main_thread', type: 'boolean', isOptional: true },
{ name: 'avatar_etag', type: 'string', isOptional: true } { name: 'avatar_etag', type: 'string', isOptional: true },
{ name: 'is_from_webview', type: 'boolean', isOptional: true }
] ]
}), }),
tableSchema({ tableSchema({

View File

@ -526,10 +526,10 @@ const RocketChat = {
return this.post('users.forgotPassword', { email }, false); return this.post('users.forgotPassword', { email }, false);
}, },
loginTOTP(params, loginEmailPassword) { loginTOTP(params, loginEmailPassword, isFromWebView = false) {
return new Promise(async(resolve, reject) => { return new Promise(async(resolve, reject) => {
try { try {
const result = await this.login(params, loginEmailPassword); const result = await this.login(params, isFromWebView);
return resolve(result); return resolve(result);
} catch (e) { } catch (e) {
if (e.data?.error && (e.data.error === 'totp-required' || e.data.error === 'totp-invalid')) { if (e.data?.error && (e.data.error === 'totp-required' || e.data.error === 'totp-invalid')) {
@ -592,15 +592,15 @@ const RocketChat = {
return this.loginTOTP(params, true); return this.loginTOTP(params, true);
}, },
async loginOAuthOrSso(params) { async loginOAuthOrSso(params, isFromWebView = true) {
const result = await this.loginTOTP(params); const result = await this.loginTOTP(params, false, isFromWebView);
reduxStore.dispatch(loginRequest({ resume: result.token })); reduxStore.dispatch(loginRequest({ resume: result.token }, false, isFromWebView));
}, },
async login(params, loginEmailPassword) { async login(credentials, isFromWebView = false) {
const sdk = this.shareSDK || this.sdk; const sdk = this.shareSDK || this.sdk;
// RC 0.64.0 // RC 0.64.0
await sdk.login(params); await sdk.login(credentials);
const { result } = sdk.currentLogin; const { result } = sdk.currentLogin;
const user = { const user = {
id: result.userId, id: result.userId,
@ -615,7 +615,7 @@ const RocketChat = {
emails: result.me.emails, emails: result.me.emails,
roles: result.me.roles, roles: result.me.roles,
avatarETag: result.me.avatarETag, avatarETag: result.me.avatarETag,
loginEmailPassword, isFromWebView,
showMessageInMainThread: result.me.settings?.preferences?.showMessageInMainThread ?? true showMessageInMainThread: result.me.settings?.preferences?.showMessageInMainThread ?? true
}; };
return user; return user;

View File

@ -97,7 +97,7 @@ const fallbackNavigation = function* fallbackNavigation() {
const handleOAuth = function* handleOAuth({ params }) { const handleOAuth = function* handleOAuth({ params }) {
const { credentialToken, credentialSecret } = params; const { credentialToken, credentialSecret } = params;
try { try {
yield RocketChat.loginOAuthOrSso({ oauth: { credentialToken, credentialSecret } }); yield RocketChat.loginOAuthOrSso({ oauth: { credentialToken, credentialSecret } }, false);
} catch (e) { } catch (e) {
log(e); log(e);
} }

View File

@ -30,15 +30,15 @@ import Navigation from '../lib/Navigation';
const getServer = state => state.server.server; const getServer = state => state.server.server;
const loginWithPasswordCall = args => RocketChat.loginWithPassword(args); const loginWithPasswordCall = args => RocketChat.loginWithPassword(args);
const loginCall = args => RocketChat.login(args); const loginCall = (credentials, isFromWebView) => RocketChat.login(credentials, isFromWebView);
const logoutCall = args => RocketChat.logout(args); const logoutCall = args => RocketChat.logout(args);
const handleLoginRequest = function* handleLoginRequest({ credentials, logoutOnError = false }) { const handleLoginRequest = function* handleLoginRequest({ credentials, logoutOnError = false, isFromWebView = false }) {
logEvent(events.LOGIN_DEFAULT_LOGIN); logEvent(events.LOGIN_DEFAULT_LOGIN);
try { try {
let result; let result;
if (credentials.resume) { if (credentials.resume) {
result = yield call(loginCall, credentials); result = yield loginCall(credentials, isFromWebView);
} else { } else {
result = yield call(loginWithPasswordCall, credentials); result = yield call(loginWithPasswordCall, credentials);
} }
@ -68,7 +68,6 @@ const handleLoginRequest = function* handleLoginRequest({ credentials, logoutOnE
log(e); log(e);
} }
}); });
yield put(loginSuccess(result)); yield put(loginSuccess(result));
} }
} catch (e) { } catch (e) {
@ -148,14 +147,13 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) {
status: user.status, status: user.status,
statusText: user.statusText, statusText: user.statusText,
roles: user.roles, roles: user.roles,
loginEmailPassword: user.loginEmailPassword, isFromWebView: user.isFromWebView,
showMessageInMainThread: user.showMessageInMainThread, showMessageInMainThread: user.showMessageInMainThread,
avatarETag: user.avatarETag avatarETag: user.avatarETag
}; };
yield serversDB.action(async() => { yield serversDB.action(async() => {
try { try {
const userRecord = await usersCollection.find(user.id); const userRecord = await usersCollection.find(user.id);
u.loginEmailPassword = userRecord?.loginEmailPassword;
await userRecord.update((record) => { await userRecord.update((record) => {
record._raw = sanitizedRaw({ id: user.id, ...record._raw }, usersCollection.schema); record._raw = sanitizedRaw({ id: user.id, ...record._raw }, usersCollection.schema);
Object.assign(record, u); Object.assign(record, u);

View File

@ -65,7 +65,7 @@ class SettingsView extends React.Component {
const usersCollection = db.get('users'); const usersCollection = db.get('users');
try { try {
const userRecord = await usersCollection.find(user.id); const userRecord = await usersCollection.find(user.id);
if (!userRecord.loginEmailPassword) { if (userRecord.isFromWebView) {
showConfirmationAlert({ showConfirmationAlert({
title: I18n.t('Clear_cookies_alert'), title: I18n.t('Clear_cookies_alert'),
message: I18n.t('Clear_cookies_desc'), message: I18n.t('Clear_cookies_desc'),