rsnext/examples/with-firebase-authentication-serverless/utils/auth/logout.js
Kevin Jennison 34f1aefa4a Add example: with-firebase-authentication-serverless (#10078)
* Start from existing example

* Upgrade some dependencies

* Use dotenv

* Remove custom server

* Add serverless Firebase auth

* Add TODOs

* Update project name

* Fix build script

* Remove server middleware from client JS bundle

* Add logout functionality

* Redirect to auth page on logout

* Remove TODO

* Add comments about the cookie-session approach

* Remove the sessions folder

* Add comments for eslint

* Remove unused files

* Clarify comment

* Update README.md

* Rename variable for clarity

* Update README.md

* Change some comments

* Add more to gitignore

* Remove the bundle analyzer

* Move server-side auth user logic from _app.js to a HOC to support static HTML rendering

Co-authored-by: Joe Haddad <timer150@gmail.com>
2020-01-20 16:12:48 -05:00

27 lines
687 B
JavaScript

/* globals window */
import firebase from 'firebase/app'
import 'firebase/auth'
export default async () => {
return firebase
.auth()
.signOut()
.then(() => {
// Sign-out successful.
if (typeof window !== 'undefined') {
// Remove the server-side rendered user data element. See:
// https://github.com/zeit/next.js/issues/2252#issuecomment-353992669
try {
const elem = window.document.getElementById('__MY_AUTH_USER_INFO')
elem.parentNode.removeChild(elem)
} catch (e) {
console.error(e)
}
}
return true
})
.catch(e => {
console.error(e)
return false
})
}