Skip to content

Commit 01c3aa9

Browse files
committed
Current user snippets
1 parent 8185ab9 commit 01c3aa9

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

auth-next/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@ function authStateListener() {
6363
// [END auth_state_listener]
6464
}
6565

66+
function currentUser() {
67+
// [START auth_current_user]
68+
const { getAuth } = require("firebase/auth");
69+
70+
const auth = getAuth();
71+
const user = auth.currentUser;
72+
73+
if (user) {
74+
// User is signed in, see docs for a list of available properties
75+
// https://firebase.google.com/docs/reference/js/firebase.User
76+
// ...
77+
} else {
78+
// No user is signed in.
79+
}
80+
// [END auth_current_user]
81+
}
82+
6683
function setLanguageCode() {
6784
// [START auth_set_language_code]
6885
const { getAuth } = require("firebase/auth");

auth/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ function authStateListener() {
5454
// [END auth_state_listener]
5555
}
5656

57+
function currentUser() {
58+
// [START auth_current_user]
59+
const user = firebase.auth().currentUser;
60+
61+
if (user) {
62+
// User is signed in, see docs for a list of available properties
63+
// https://firebase.google.com/docs/reference/js/firebase.User
64+
// ...
65+
} else {
66+
// No user is signed in.
67+
}
68+
// [END auth_current_user]
69+
}
70+
5771
function setLanguageCode() {
5872
// [START auth_set_language_code]
5973
firebase.auth().languageCode = 'it';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// This snippet file was generated by processing the source file:
2+
// ./auth-next/index.js
3+
//
4+
// To make edits to the snippets in this file, please edit the source
5+
6+
// [START auth_current_user_modular]
7+
import { getAuth } from "firebase/auth";
8+
9+
const auth = getAuth();
10+
const user = auth.currentUser;
11+
12+
if (user) {
13+
// User is signed in, see docs for a list of available properties
14+
// https://firebase.google.com/docs/reference/js/firebase.User
15+
// ...
16+
} else {
17+
// No user is signed in.
18+
}
19+
// [END auth_current_user_modular]

0 commit comments

Comments
 (0)