MOBILE-3645 login: Fix consecutive logins if logout+SSO

main
Dani Palou 2021-03-17 14:14:30 +01:00
parent 0a5ca792b9
commit 45a23eff88
2 changed files with 14 additions and 9 deletions

View File

@ -211,11 +211,11 @@ export type SiteDBEntry = {
id: string; id: string;
siteUrl: string; siteUrl: string;
token: string; token: string;
info: string; info?: string | null;
privateToken: string; privateToken: string;
config: string; config?: string | null;
loggedOut: number; loggedOut: number;
oauthId: number; oauthId?: number | null;
}; };
export type CurrentSiteDBEntry = { export type CurrentSiteDBEntry = {

View File

@ -688,7 +688,7 @@ export class CoreSitesProvider {
oauthId?: number, oauthId?: number,
): Promise<void> { ): Promise<void> {
const db = await this.appDB; const db = await this.appDB;
const entry = { const entry: SiteDBEntry = {
id, id,
siteUrl, siteUrl,
token, token,
@ -1004,7 +1004,7 @@ export class CoreSitesProvider {
const config = entry.config ? <CoreSiteConfig> CoreTextUtils.parseJSON(entry.config) : undefined; const config = entry.config ? <CoreSiteConfig> CoreTextUtils.parseJSON(entry.config) : undefined;
const site = new CoreSite(entry.id, entry.siteUrl, entry.token, info, entry.privateToken, config, entry.loggedOut == 1); const site = new CoreSite(entry.id, entry.siteUrl, entry.token, info, entry.privateToken, config, entry.loggedOut == 1);
site.setOAuthId(entry.oauthId); site.setOAuthId(entry.oauthId || undefined);
return this.migrateSiteSchemas(site).then(() => { return this.migrateSiteSchemas(site).then(() => {
// Set site after migrating schemas, or a call to getSite could get the site while tables are being created. // Set site after migrating schemas, or a call to getSite could get the site while tables are being created.
@ -1221,11 +1221,16 @@ export class CoreSitesProvider {
async setSiteLoggedOut(siteId: string, loggedOut: boolean): Promise<void> { async setSiteLoggedOut(siteId: string, loggedOut: boolean): Promise<void> {
const db = await this.appDB; const db = await this.appDB;
const site = await this.getSite(siteId); const site = await this.getSite(siteId);
const newValues = { const newValues: Partial<SiteDBEntry> = {
token: '', // Erase the token for security.
loggedOut: loggedOut ? 1 : 0, loggedOut: loggedOut ? 1 : 0,
}; };
if (loggedOut) {
// Erase the token for security.
newValues.token = '';
site.token = '';
}
site.setLoggedOut(loggedOut); site.setLoggedOut(loggedOut);
await db.updateRecords(SITES_TABLE_NAME, newValues, { id: siteId }); await db.updateRecords(SITES_TABLE_NAME, newValues, { id: siteId });
@ -1266,7 +1271,7 @@ export class CoreSitesProvider {
async updateSiteTokenBySiteId(siteId: string, token: string, privateToken: string = ''): Promise<void> { async updateSiteTokenBySiteId(siteId: string, token: string, privateToken: string = ''): Promise<void> {
const db = await this.appDB; const db = await this.appDB;
const site = await this.getSite(siteId); const site = await this.getSite(siteId);
const newValues = { const newValues: Partial<SiteDBEntry> = {
token, token,
privateToken, privateToken,
loggedOut: 0, loggedOut: 0,
@ -1307,7 +1312,7 @@ export class CoreSitesProvider {
// Error getting config, keep the current one. // Error getting config, keep the current one.
} }
const newValues: Record<string, string | number> = { const newValues: Partial<SiteDBEntry> = {
info: JSON.stringify(info), info: JSON.stringify(info),
loggedOut: site.isLoggedOut() ? 1 : 0, loggedOut: site.isLoggedOut() ? 1 : 0,
}; };