gristlabs_grist-core/app/common/LoginSessionAPI.ts
Jarosław Sadziński 0bdc838975 (core) New look for site switcher in top-left corner, with support for per-org logos
Summary:
  - Site switcher will show initials (either from user's name or team name),
  - Anonymous users see a grist logo on personal site, but team logo (or initials) on team site,
  - Admin pages (and other pages without orgs) show grist logo,
  - Custom image can be switched on the billing page, common formats are supported up to 100KB.
  - Larger images are down-scaled (on the front-end)
  - SVG larger than 100KB are not accepted
  - Files are stored as data URL's in org prefs,

Test Plan: Added new tests

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D4341
2024-10-08 10:43:26 +02:00

53 lines
2.0 KiB
TypeScript

import {normalizeEmail} from 'app/common/emails';
import {UserPrefs} from 'app/common/Prefs';
// User profile info for the user. When using Cognito, it is fetched during login.
export interface UserProfile {
email: string; // TODO: Used inconsistently: as lowercase login email or display email.
name: string;
loginEmail?: string; // When set, this is consistently normalized (lowercase) login email.
picture?: string|null; // when present, a url to a public image of unspecified dimensions.
anonymous?: boolean; // when present, asserts whether user is anonymous (not authorized).
connectId?: string|null, // used by GristConnect to identify user in external provider.
loginMethod?: 'Google'|'Email + Password'|'External';
locale?: string|null;
}
/**
* Tries to compare two user profiles to see if they represent the same user.
* Note: if you have access to FullUser objects, comparing ids is more reliable.
*/
export function sameUser(a: UserProfile|FullUser, b: UserProfile|FullUser): boolean {
if ('id' in a && 'id' in b) {
return a.id === b.id;
}
if (a.loginEmail && b.loginEmail) {
return a.loginEmail === b.loginEmail;
} else {
return normalizeEmail(a.email) === normalizeEmail(b.email);
}
}
// User profile including user id and user ref. All information in it should
// have been validated against database.
export interface FullUser extends UserProfile {
id: number;
ref?: string|null; // Not filled for anonymous users.
allowGoogleLogin?: boolean; // when present, specifies whether logging in via Google is possible.
isSupport?: boolean; // set if user is a special support user.
prefs?: UserPrefs;
}
export interface LoginSessionAPI {
/**
* Logs out by clearing all data in the session store besides the session cookie itself.
* Broadcasts the logged out state to all clients.
*/
logout(): Promise<void>;
/**
* Replaces the user profile object in the session and broadcasts the new profile to all clients.
*/
updateProfile(profile: UserProfile): Promise<void>;
}