34f1aefa4a
* 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>
27 lines
687 B
JavaScript
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
|
|
})
|
|
}
|