mirror of
https://github.com/jlengrand/web-brain.git
synced 2026-03-10 08:51:21 +00:00
Caches auth
This commit is contained in:
@@ -4,12 +4,15 @@ import { customElement, property } from 'lit/decorators.js';
|
|||||||
import { FirebaseApp, initializeApp } from 'firebase/app';
|
import { FirebaseApp, initializeApp } from 'firebase/app';
|
||||||
import {
|
import {
|
||||||
getAuth,
|
getAuth,
|
||||||
|
setPersistence,
|
||||||
signInWithPopup,
|
signInWithPopup,
|
||||||
signOut,
|
signOut,
|
||||||
GoogleAuthProvider,
|
GoogleAuthProvider,
|
||||||
Auth,
|
Auth,
|
||||||
AuthProvider,
|
AuthProvider,
|
||||||
User,
|
User,
|
||||||
|
browserLocalPersistence,
|
||||||
|
onAuthStateChanged
|
||||||
} from 'firebase/auth';
|
} from 'firebase/auth';
|
||||||
|
|
||||||
import { FIREBASE_CONFIG } from './constants.js';
|
import { FIREBASE_CONFIG } from './constants.js';
|
||||||
@@ -33,14 +36,19 @@ export class WebBrain extends LitElement {
|
|||||||
this.firebaseApp = initializeApp(FIREBASE_CONFIG);
|
this.firebaseApp = initializeApp(FIREBASE_CONFIG);
|
||||||
|
|
||||||
this.auth = getAuth();
|
this.auth = getAuth();
|
||||||
|
|
||||||
|
onAuthStateChanged(this.auth, (user) => {
|
||||||
|
console.log(`onAuthStateChanged${user}`);
|
||||||
|
if (user) { this.user = user;}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static styles = css``;
|
static styles = css``;
|
||||||
|
|
||||||
async logIn() {
|
async logIn() {
|
||||||
console.log('Logging in');
|
console.log('Logging in');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
await setPersistence(this.auth,browserLocalPersistence);
|
||||||
const result = await signInWithPopup(this.auth, this.provider);
|
const result = await signInWithPopup(this.auth, this.provider);
|
||||||
console.log('logged in');
|
console.log('logged in');
|
||||||
this.user = result.user;
|
this.user = result.user;
|
||||||
|
|||||||
Reference in New Issue
Block a user