UNPKG

4.9 kBTypeScriptView Raw
1import { ExpoConfig } from '@expo/config-types';
2import { FeatureGating, Semaphore, UserData } from './internal';
3export declare type User = {
4 kind: 'user';
5 username: string;
6 nickname: string;
7 userId: string;
8 picture: string;
9 email?: string;
10 emailVerified?: boolean;
11 givenName?: string;
12 familyName?: string;
13 userMetadata: {
14 onboarded: boolean;
15 legacy?: boolean;
16 };
17 currentConnection: ConnectionType;
18 sessionSecret?: string;
19 accessToken?: string;
20};
21export declare type RobotUser = {
22 kind: 'robot';
23 userId: string;
24 username: string;
25 givenName?: string;
26 currentConnection: ConnectionType;
27 sessionSecret?: never;
28 accessToken?: string;
29};
30export declare type LegacyUser = {
31 kind: 'legacyUser';
32 username: string;
33 userMetadata: {
34 legacy: boolean;
35 needsPasswordMigration: boolean;
36 };
37};
38export declare type UserOrLegacyUser = User | LegacyUser;
39export declare type ConnectionType = 'Access-Token-Authentication' | 'Username-Password-Authentication' | 'facebook' | 'google-oauth2' | 'github';
40export declare type RegistrationData = {
41 username: string;
42 password: string;
43 email?: string;
44 givenName?: string;
45 familyName?: string;
46};
47export declare type LoginType = 'user-pass' | 'facebook' | 'google' | 'github';
48export declare const ANONYMOUS_USERNAME = "anonymous";
49export declare class UserManagerInstance {
50 _currentUser: User | RobotUser | null;
51 _getSessionLock: Semaphore;
52 _interactiveAuthenticationCallbackAsync?: () => Promise<User>;
53 static getGlobalInstance(): UserManagerInstance;
54 initialize(): void;
55 /**
56 * Get the account and project name using a user and Expo config.
57 * This will validate if the owner field is set when using a robot account.
58 */
59 getProjectOwner(user: User | RobotUser, exp: ExpoConfig): string;
60 /**
61 * Logs in a user for a given login type.
62 *
63 * Valid login types are:
64 * - "user-pass": Username and password authentication
65 *
66 * If the login type is "user-pass", we directly make the request to www
67 * to login a user.
68 */
69 loginAsync(loginType: LoginType, loginArgs?: {
70 username: string;
71 password: string;
72 otp?: string;
73 }): Promise<User>;
74 registerAsync(userData: RegistrationData, user?: UserOrLegacyUser | null): Promise<User>;
75 /**
76 * Ensure user is logged in and has a valid token.
77 *
78 * If there are any issues with the login, this method throws.
79 */
80 ensureLoggedInAsync(): Promise<User | RobotUser>;
81 setInteractiveAuthenticationCallback(callback: () => Promise<User>): void;
82 _readUserData(): Promise<UserData | null>;
83 /**
84 * Returns cached user data without hitting our backend. Only works for 'Username-Password-Authentication' flow. Does not work with 'Access-Token-Authentication' flow.
85 */
86 getCachedUserDataAsync: () => Promise<UserData | null>;
87 /**
88 * Get the current user based on the available token.
89 * If there is no current token, returns null.
90 */
91 getCurrentUserAsync(options?: {
92 silent?: boolean;
93 }): Promise<User | RobotUser | null>;
94 /**
95 * Get the current user and check if it's a robot.
96 * If the user is not a robot, it will throw an error.
97 */
98 getCurrentUserOnlyAsync(): Promise<User | null>;
99 /**
100 * Get the current user and check if it's a robot.
101 * If the user is not a robot, it will throw an error.
102 */
103 getCurrentRobotUserOnlyAsync(): Promise<RobotUser | null>;
104 getCurrentUsernameAsync(): Promise<string | null>;
105 getSessionAsync(): Promise<{
106 sessionSecret?: string;
107 accessToken?: string;
108 } | null>;
109 /**
110 * Create or update a user.
111 */
112 createOrUpdateUserAsync(userData: object): Promise<User | null>;
113 /**
114 * Logout
115 */
116 logoutAsync(): Promise<void>;
117 getFeatureGatingAsync(): Promise<FeatureGating>;
118 /**
119 * Forgot Password
120 */
121 forgotPasswordAsync(usernameOrEmail: string): Promise<void>;
122 /**
123 * Get profile given token data. Errors if token is not valid or if no
124 * user profile is returned.
125 *
126 * This method is called by all public authentication methods of `UserManager`
127 * except `logoutAsync`. Therefore, we use this method as a way to:
128 * - update the UserSettings store with the current token and user id
129 * - update UserManager._currentUser
130 * - Fire login analytics events
131 *
132 * Also updates UserManager._currentUser.
133 *
134 * @private
135 */
136 _getProfileAsync({ currentConnection, sessionSecret, accessToken, }: {
137 currentConnection?: ConnectionType;
138 sessionSecret?: string;
139 accessToken?: string;
140 }): Promise<User | RobotUser>;
141}
142declare const _default: UserManagerInstance;
143export default _default;