Skip to content

[@nativescript/google-signin] Google Sign In v2.1.1 error in Nativescript (Core/Plain) v8.9.1 #630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dyazincahya opened this issue May 30, 2025 · 5 comments
Labels
question Further information is requested

Comments

@dyazincahya
Copy link

Info

  • Google Sign In v2.1.1
  • Nativescript (Core/Plain) v8.9.1

Code

<Page xmlns:ui="@nativescript/google-signin">
	<ActionBar title="Google Sign-In" class="action-bar" />
	<StackLayout class="p-20">
		<ui:GoogleSigninButton tap="handleSignIn" colorScheme='auto' colorStyle='standard'/>
	</StackLayout>
</Page>
import { GoogleSignin } from "@nativescript/google-signin";

export async function handleSignIn() {
  await GoogleSignin.configure({
    scopes: ["https://www.googleapis.com/auth/drive.file"],
    webClientId:
      "123..............-......................apps.googleusercontent.com",
    offlineAccess: true,
  });

  const userInfo = await GoogleSignin.signIn();
  const tokens = await GoogleSignin.getTokens();

}

Error

Exception

Image

Logcat

Image

@NathanWalker
Copy link
Contributor

NathanWalker commented May 30, 2025

I think this may be due to your example calling configure in the tap there? Just ran on API Level 35, Pixel 6 and can confirm it works well here with plain XML - can just call const user = await GoogleSignin.signIn(); inside the tap.

googlesignin.mov

@NathanWalker NathanWalker added the question Further information is requested label May 30, 2025
@dyazincahya
Copy link
Author

dyazincahya commented May 30, 2025

I think this may be due to your example calling configure in the tap there? Just ran on API Level 35, Pixel 6 and can confirm it works well here with plain XML - can just call const user = await GoogleSignin.signIn(); inside the tap.

googlesignin.mov

Am using bluestack for emulator, & Andoid Pie, does it matter? And what's wrong about my configure?

Btw, the above error appears before the page containing the sign-in button is displayed.

@dyazincahya
Copy link
Author

dyazincahya commented May 30, 2025

Full Code

login.js

import { Application } from "@nativescript/core";

import { login as googleLogin } from "~/google";

import { GlobalModel } from "~/global_model";

var context = new GlobalModel([{ page: "Backup-restore" }]);

export function onLoaded() {
  // loadMyAdMob();
}

export function onNavigatingTo(args) {
  const page = args.object;

  page.bindingContext = context;
}

export function onDrawerButtonTap(args) {
  const sideDrawer = Application.getRootView();
  sideDrawer.showDrawer();
}

export function handleSignIn() {
  googleLogin()
    .then(({ userInfo }) => {
      console.log("Login sukses!", userInfo);
    })
    .catch((err) => {
      console.error("Login gagal:", err);
    });
}

login.xml

<Page
	loaded="onLoaded"
	navigatingTo="onNavigatingTo"
	xmlns="http://schemas.nativescript.org/tns.xsd" 

	xmlns:ui="@nativescript/google-signin">

	<ActionBar flat="true">
		<NavigationButton visibility="hidden"></NavigationButton>
		<GridLayout columns="50, auto, *, auto, 5, auto, 10">
			<Label class="fas" text="&#xf036;" tap="onDrawerButtonTap" col="0" />
			<Label class="action-bar-title ubuntu-bold" text="Backup &amp; Restore" tap="onDrawerButtonTap" col="1"/>
		</GridLayout>
	</ActionBar>

	<GridLayout rows="auto, 10, *, 10">
		<ScrollView row="0">
			<StackLayout margin="10 0">
				<ui:GoogleSigninButton tap="handleSignIn" colorScheme='auto' colorStyle='standard'/>
			</StackLayout>
		</ScrollView>
	</GridLayout>
</Page>

Helper google.js

import { knownFolders, Http } from "@nativescript/core";
import { GoogleSignin } from "@nativescript/google-signin";

export async function login() {
  await GoogleSignin.configure({
    scopes: ["https://www.googleapis.com/auth/drive.file"],
    webClientId:
      "12345-xxxxxxxxx.apps.googleusercontent.com",
    offlineAccess: true,
  });

  const userInfo = await GoogleSignin.signIn();
  const tokens = await GoogleSignin.getTokens();

  return {
    userInfo,
    accessToken: tokens.accessToken,
  };
}

export async function logout() {
  await GoogleSignin.signOut();
}

export async function uploadToDrive(accessToken, localPath, remoteName) {
  const file = knownFolders.documents().getFile(localPath);
  const content = file.readSync((err) => {
    if (err) throw err;
  });

  const metadata = {
    name: remoteName,
    mimeType: "application/x-sqlite3",
  };

  const boundary = "-------314159265358979323846";
  const delimiter = `\r\n--${boundary}\r\n`;
  const closeDelimiter = `\r\n--${boundary}--`;

  const body =
    delimiter +
    "Content-Type: application/json\r\n\r\n" +
    JSON.stringify(metadata) +
    delimiter +
    "Content-Type: application/x-sqlite3\r\n\r\n" +
    content +
    closeDelimiter;

  const response = await Http.request({
    url: "https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart",
    method: "POST",
    headers: {
      Authorization: `Bearer ${accessToken}`,
      "Content-Type": `multipart/related; boundary=${boundary}`,
    },
    content: body,
  });

  return response;
}

export async function downloadFromDrive(fileId, accessToken, saveAsFilename) {
  const response = await Http.request({
    url: `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media`,
    method: "GET",
    headers: {
      Authorization: `Bearer ${accessToken}`,
    },
  });

  const file = knownFolders.documents().getFile(saveAsFilename);
  file.writeSync(response.content.toUint8Array());

  return file.path;
}

@dyazincahya
Copy link
Author

I try to hit this method await GoogleSignin.signIn();, I have an error like this

Image

@dyazincahya
Copy link
Author

I been to added sha1 and sha256 to firebase too

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants