MOBILE-3645 login: Fix consecutive logins if logout+SSO
parent
0a5ca792b9
commit
45a23eff88
|
@ -211,11 +211,11 @@ export type SiteDBEntry = {
|
|||
id: string;
|
||||
siteUrl: string;
|
||||
token: string;
|
||||
info: string;
|
||||
info?: string | null;
|
||||
privateToken: string;
|
||||
config: string;
|
||||
config?: string | null;
|
||||
loggedOut: number;
|
||||
oauthId: number;
|
||||
oauthId?: number | null;
|
||||
};
|
||||
|
||||
export type CurrentSiteDBEntry = {
|
||||
|
|
|
@ -688,7 +688,7 @@ export class CoreSitesProvider {
|
|||
oauthId?: number,
|
||||
): Promise<void> {
|
||||
const db = await this.appDB;
|
||||
const entry = {
|
||||
const entry: SiteDBEntry = {
|
||||
id,
|
||||
siteUrl,
|
||||
token,
|
||||
|
@ -1004,7 +1004,7 @@ export class CoreSitesProvider {
|
|||
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);
|
||||
site.setOAuthId(entry.oauthId);
|
||||
site.setOAuthId(entry.oauthId || undefined);
|
||||
|
||||
return this.migrateSiteSchemas(site).then(() => {
|
||||
// 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> {
|
||||
const db = await this.appDB;
|
||||
const site = await this.getSite(siteId);
|
||||
const newValues = {
|
||||
token: '', // Erase the token for security.
|
||||
const newValues: Partial<SiteDBEntry> = {
|
||||
loggedOut: loggedOut ? 1 : 0,
|
||||
};
|
||||
|
||||
if (loggedOut) {
|
||||
// Erase the token for security.
|
||||
newValues.token = '';
|
||||
site.token = '';
|
||||
}
|
||||
|
||||
site.setLoggedOut(loggedOut);
|
||||
|
||||
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> {
|
||||
const db = await this.appDB;
|
||||
const site = await this.getSite(siteId);
|
||||
const newValues = {
|
||||
const newValues: Partial<SiteDBEntry> = {
|
||||
token,
|
||||
privateToken,
|
||||
loggedOut: 0,
|
||||
|
@ -1307,7 +1312,7 @@ export class CoreSitesProvider {
|
|||
// Error getting config, keep the current one.
|
||||
}
|
||||
|
||||
const newValues: Record<string, string | number> = {
|
||||
const newValues: Partial<SiteDBEntry> = {
|
||||
info: JSON.stringify(info),
|
||||
loggedOut: site.isLoggedOut() ? 1 : 0,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue