react-native-google-signin
Version:
Google Signin for your react native applications
85 lines (75 loc) • 2.35 kB
Flow
// @flow
import * as React from 'react';
import type { ViewProps } from 'ViewPropTypes';
export type ConfigureParams = $ReadOnly<{|
iosClientId?: string,
offlineAccess?: boolean,
webClientId?: string,
scopes?: string[],
loginHint?: string,
hostedDomain?: string,
forceConsentPrompt?: boolean,
accountName?: string,
|}>;
export type GoogleSigninButtonProps = $ReadOnly<{|
...ViewProps,
size?: number,
color?: string,
disabled?: boolean,
onPress?: () => any,
|}>;
declare export class GoogleSigninButton extends React$Component<GoogleSigninButtonProps> {
static Size: {
Icon: number,
Standard: number,
Wide: number,
};
static Color: {
Auto: string,
Light: string,
Dark: string,
};
}
export type HasPlayServicesParams = $ReadOnly<{|
showPlayServicesUpdateDialog: boolean,
|}>;
export type User = {|
user: {|
id: string,
name: ?string, // full name
email: string,
photo: ?string, // url
familyName: ?string,
givenName: ?string,
|},
scopes: string[], // on iOS this is empty array if no additional scopes are defined
idToken: string,
/**
* Not null only if a valid webClientId and offlineAccess: true was
* specified in configure().
*/
serverAuthCode: ?string,
|};
// Android Status codes: https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInStatusCodes
type StatusCodes = $ReadOnly<{
SIGN_IN_CANCELLED: string,
IN_PROGRESS: string,
PLAY_SERVICES_NOT_AVAILABLE: string,
SIGN_IN_REQUIRED: string,
}>;
declare export var statusCodes: StatusCodes;
// the functions are not static in fact, but the module exports a
// singleton instance of the class; not the class itself
// using static keyword works well for this case
declare export class GoogleSignin {
static hasPlayServices: (params?: HasPlayServicesParams) => Promise<boolean>;
static configure: (params?: ConfigureParams) => void;
static signInSilently: () => Promise<User>;
static signIn: () => Promise<User>;
static signOut: () => Promise<null>;
static revokeAccess: () => Promise<null>;
static isSignedIn: () => Promise<boolean>;
static getCurrentUser(): Promise<User | null>;
static clearCachedToken(token: string): Promise<null>;
static getTokens(): Promise<{ idToken: string, accessToken: string }>;
}