I have this function:
function handleLoginSuccess(response: GoogleLoginResponse | GoogleLoginResponseOffline ) {
const { access_token } = response.tokenObj;
console.log(response.getAuthResponse());
setIsLoggedIn(true);
}
So, i want to get the tokenObj from the response. It is declared in the GoogleLoginResponse interface but not in the GoogleLoginReponseOffline. How can i access this property in this method?
I am passing it as a parameter of another function that expects this signature. So it is not possible to be changed.
GoogleLoginResponse Interface:
export interface GoogleLoginResponse {
getBasicProfile(): BasicProfile;
getAuthResponse(): AuthResponse;
reloadAuthResponse(): Promise<AuthResponse>;
getGrantedScopes(): string;
getHostedDomain(): string;
getId(): string;
isSignedIn(): boolean;
hasGrantedScopes(scopes: string): boolean;
disconnect(): void;
grantOfflineAccess(options: GrantOfflineAccessOptions): Promise<GoogleLoginResponseOffline>;
signIn(options: SignInOptions): Promise<any>;
grant(options: SignInOptions): Promise<any>;
// google-login.js sez: offer renamed response keys to names that match use
googleId: string;
tokenObj: AuthResponse;
tokenId: string;
accessToken: string;
profileObj: {
googleId: string;
imageUrl: string;
email: string;
name: string;
givenName: string;
familyName: string;
}
}
GoogleLoginResponseOffline interface
export interface GoogleLoginResponseOffline {
readonly code: string;
}
How can I proceed with this? I am using the https://github.com/anthonyjgrove/react-google-login library
Edit: I fixed it adding the any type in the method definition
function handleLoginSuccess(response: any) {
// implementation
}
But I am not comfortable to use the "any" type there