首页 > 解决方案 > 使用 Angular 实现 Google One Tap Login

问题描述

navbar.template.html

   <div id="g_id_onload"
         data-client_id="832#################m921.apps.googleusercontent.com"
         data-cancel_on_tap_outside="false"
         data-login_uri="http://localhost:3010/auth/g-one-tap"
         data-callback="handleCredentialResponse">
    </div>

API 获得响应我能够验证用户并返回经过验证的 JWT 令牌,我如何捕获响应并避免页面重定向到http://localhost:3010/auth/g-one-tap

我怎样才能在 typsecript 文件中使用一些单击功能,这有助于遵循我之前使用 google 登录按钮使用的正常登录流程。

 public socialSignIn(responseData) {
         this.googleSubscription = this._globalService.googleLogin(responseData)
                .subscribe(
                    data => {
                        if (data['success']) {
                            const token = data['data']['token'];

                            if (this.platformId === 'browser') {
                               // login to save the token
                            }

                        }
                    },
                    error => {
                        console.log('error');
                    }
                );
    }

标签: google-oauthgoogle-signingoogle-authentication

解决方案


如此处所述,您不应同时使用 data-login_uri 和 data-callbck 属性。

您需要删除代码中的 data-login_uri 属性。如果还没有,请提供回调函数的实现(在您的代码中其名称是 handleCredentialResponse)。


推荐阅读