隐藏登录谷歌's "欢迎回来,{name}"
Hiding Sign In With Google's "Welcome back, {name}"
如何使欢迎返回消息不会在每次用户导航到新页面时出现?
有问题的消息
编辑:添加了代码,但它的所有基本的东西,以获得用户登录。
回调:
function signInCallback(authResult) {
gapi.client.load('plus','v1', function(){
if (authResult['status']['signed_in']) {
// Update the app to reflect a signed in user
// Hide the sign-in button now that the user is authorized, for example:
$('#gConnect').hide();
$('#authOps').show('slow');
setProfileInfo(firstName);
isUserInDatabase();
console.log(authResult);
} else {
// Update the app to reflect a signed out user
// Possible error values:
// "user_signed_out" - User is signed-out
// "access_denied" - User denied access to your app
// "immediate_failed" - Could not automatically log in the user
console.log('Sign-in state: ' + authResult['error']);
}
});
}
登录按钮:
<div id="gConnect">
<button class="g-signin"
data-scope="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-clientId="819876183778-b7cuojcnn2fsi1rcm9k8sshnsebic68e.apps.googleusercontent.com"
data-callback="signInCallback"
data-theme="dark"
data-cookiepolicy="single_host_origin">
</button>
</div>
加载Google+ API:
<script type="text/javascript">
(function() {
var po = document.createElement('script');
po.type = 'text/javascript'; po.async = true;
po.src = 'https://plus.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
</script>
所以我建议跟踪用户的已登录状态(本地存储或服务器端标志),并且仅在状态从未登录更改为已登录时显示消息
相关文章:
- 铬:“;未捕获的语法错误:意外的标记:"
- 如果localstorage为空,则显示欢迎消息
- 可以设置“;文件名"发生错误时显示的内联脚本标记的
- JS表单提交"无法使用Chrome数据保护程序加载此页面.尝试重新加载页面.调试信息:POST CISmtuK
- 检测电话窃听,即:<a href="电话:xxx">在UIWebview上
- 使用“+="操作人员
- //而不是在src=“”上使用http://"属性
- "未捕获的语法错误:意外的标记}"
- 可以<脚本类型=“;text/javascript”>window.location=“/"</
- "实例范围”;TypeScript类的getter/setter
- Javascript复选框函数:;缺少:在属性id之后"
- "“;变量未引用正确的对象
- "日期“;AJAX请求返回的类型值未定义
- 得到"TypeError:无法读取属性'filename'未定义的“;调用“npm start
- Soundcloud api"未捕获的类型错误:无法读取属性'uri'“未定义”;
- "工具提示"jQuery插件坏了
- "锻造;React中的表达式
- 图像可以从源<img src=""/>.TEXT可以在没有javascript的情况下从外部
- 如何提取“;href"最近列表项中的属性值
- 隐藏登录谷歌's "欢迎回来,{name}"