google-oauth - 使用 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');
}
);
}
解决方案
如此处所述,您不应同时使用 data-login_uri 和 data-callbck 属性。
您需要删除代码中的 data-login_uri 属性。如果还没有,请提供回调函数的实现(在您的代码中其名称是 handleCredentialResponse)。
推荐阅读
- twitter-bootstrap - Boostrap 模板缩放图像滑块
- r - 无法使用 rvest 抓取带有表单的网站
- flutter - 右侧溢出 17 个像素的 renderflex
- kotlin - sortedWith() 扩展函数中 Kotlin 中的逆变
- reactjs - 在 React 中旋转 Globe.gl 地球仪(使用 react-three-fiber 或其他方式)
- javascript - 表单验证 - 带有 patterMismatch 的函数不显示错误
- xml - 如何在 XSD 中使用没有包装器元素的 complexType?
- job-scheduling - 具有相同计划的控制 M 循环作业不应并行运行
- java - GET 请求中的过滤器
- javascript - 加载外部安全网站并获取特定 id 来设置值?