-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathauth-state-persistence.js
45 lines (42 loc) · 1.57 KB
/
auth-state-persistence.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// These samples are intended for Web so this import would normally be
// done in HTML however using modules here is more convenient for
// ensuring sample correctness offline.
import firebase from "firebase/app";
import "firebase/auth";
function setPersistenceSession() {
var email = "...";
var password = "...";
// [START auth_set_persistence_session]
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION)
.then(() => {
// Existing and future Auth states are now persisted in the current
// session only. Closing the window would clear any existing state even
// if a user forgets to sign out.
// ...
// New sign-in will be persisted with session persistence.
return firebase.auth().signInWithEmailAndPassword(email, password);
})
.catch((error) => {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
});
// [END auth_set_persistence_session]
}
function setPersistenceNone() {
// [START auth_set_persistence_none]
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.NONE)
.then(() => {
var provider = new firebase.auth.GoogleAuthProvider();
// In memory persistence will be applied to the signed in Google user
// even though the persistence was set to 'none' and a page redirect
// occurred.
return firebase.auth().signInWithRedirect(provider);
})
.catch((error) => {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
});
// [END auth_set_persistence_none]
}