简体   繁体   English

如何在Firebase中添加注销选项

[英]How to add SignOut option in firebase

First of all, I'm sorry if this has already been asked but I searched a lot and couldn't find anything. 首先,对不起,如果已经有人问过我,但是我搜索了很多,却找不到任何东西。 Basically, I have this code that lets me log in but I can't log out, I searched and tried different codes but it didn't work. 基本上,我有这段代码可以登录,但我无法注销,我搜索并尝试了不同的代码,但是没有用。 Could anyone please help. 谁能帮忙。

 initApp = function() { firebase.auth().onAuthStateChanged(function(user) { if (user) { // User is signed in. var displayName = user.displayName; var email = user.email; var emailVerified = user.emailVerified; var photoURL = user.photoURL; var uid = user.uid; var phoneNumber = user.phoneNumber; var providerData = user.providerData; document.getElementById("name-container").innerHTML=displayName; } else { // User is signed out. } }, function(error) { console.log(error); }); }; window.addEventListener('load', function() { initApp() }); 
 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Login</title> <style type="text/css"> @import url('https://fonts.googleapis.com/css?family=Dosis'); body{ margin: 0; font-family: 'Dosis', sans-serif; } #header{ width: 100%; height: 100px; padding-top: 50px; text-align: center; color: black; font-size: 34px; box-shadow: 10px 10px 5px #aaaaaa; } h2{ margin: 0; } .container{ width: 100%; text-align: center; margin-top: 90px; } .first{ display: table; margin: 0 auto; text-align: center; padding: 20px; } a{ text-decoration: none; font-size: 30px; color: red; } a:hover{ color: black; } p{ text-decoration: none; font-size: 30px; color: red; } p:hover{ color: black; cursor: pointer; } footer{ text-align: center; border-top: 1px solid black; padding: 20px; position: fixed; bottom: 0; left: 0 right:0; width: 100%; } </style> <script src="https://www.gstatic.com/firebasejs/5.5.7/firebase.js"></script> <script type="text/javascript" src="app.js"></script> </head> <body> <div id="header"> <h2>Welcome <span id="name-container"></span></h2> </div> <div class="container"> <div class="first"> <a href="">Account</a> </div> <div class="first"> <a href="">My Files</a> </div> <div class="first"> <p class="first">LogOut</p> </div> </div> <footer> Smarter © 2018 </footer> </body> </html> 

I just want to know how can I implement the signout option. 我只想知道如何实现注销选项。

To sign the user out of Firebase Authentication, call firebase.auth().signOut() . 要注销用户的Firebase身份验证,请调用firebase.auth().signOut() See for a longer example the bottom of this page: https://firebase.google.com/docs/auth/web/password-auth . 有关更长的示例,请参见本页底部: https : //firebase.google.com/docs/auth/web/password-auth

Note that this doesn't sign the user out of Google Authentication. 请注意,这不会使用户退出Google身份验证。 If you want to do that too (you typically won't), see https://developers.google.com/identity/sign-in/web/sign-in#sign_out_a_user 如果您也想这样做(通常不会这样做),请参阅https://developers.google.com/identity/sign-in/web/sign-in#sign_out_a_user

You can use firebase.auth().signOut() method to sign out users. 您可以使用firebase.auth().signOut()方法注销用户。

Read more from official documentation about authentication. 从官方文档中获取有关身份验证的更多信息。 https://firebase.google.com/docs/reference/js/firebase.auth.Auth https://firebase.google.com/docs/reference/js/firebase.auth.Auth

use FirebaseAuth.signOut() on your logout click 在您的登出点击上使用FirebaseAuth.signOut()

See more on this documention 有关此文档的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM