Skip to content

Commit 4126f18

Browse files
authored
Add snippet for Auth Emulator + Google Credential (#213)
1 parent 3c57ca8 commit 4126f18

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

auth-next/emulator-suite.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,15 @@ function emulatorConnect() {
1010
// [END auth_emulator_connect]
1111
}
1212

13+
function emulatorGoogleCredential() {
14+
// [START auth_emulator_google_credential]
15+
const { getAuth, signInWithCredential, GoogleAuthProvider } = require("firebase/auth");
16+
17+
const auth = getAuth();
18+
signInWithCredential(auth, GoogleAuthProvider.credential(
19+
'{"sub": "abc123", "email": "[email protected]", "email_verified": true}'
20+
));
21+
// [END auth_emulator_google_credential]
22+
}
23+
24+

auth/emulator-suite.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@ import "firebase/auth";
33

44
function emulatorConnect() {
55
// [START auth_emulator_connect]
6-
var auth = firebase.auth();
6+
const auth = firebase.auth();
77
auth.useEmulator("http://localhost:9099");
88
// [END auth_emulator_connect]
99
}
10+
11+
function emulatorGoogleCredential() {
12+
// [START auth_emulator_google_credential]
13+
const auth = firebase.auth();
14+
auth.signInWithCredential(firebase.auth.GoogleAuthProvider.credential(
15+
'{"sub": "abc123", "email": "[email protected]", "email_verified": true}'
16+
));
17+
// [END auth_emulator_google_credential]
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// This snippet file was generated by processing the source file:
2+
// ./auth-next/emulator-suite.js
3+
//
4+
// To update the snippets in this file, edit the source and then run
5+
// 'npm run snippets'.
6+
7+
// [START auth_emulator_google_credential_modular]
8+
import { getAuth, signInWithCredential, GoogleAuthProvider } from "firebase/auth";
9+
10+
const auth = getAuth();
11+
signInWithCredential(auth, GoogleAuthProvider.credential(
12+
'{"sub": "abc123", "email": "[email protected]", "email_verified": true}'
13+
));
14+
// [END auth_emulator_google_credential_modular]

0 commit comments

Comments
 (0)