Day 1 of 5
⏱ ~60 minutes
Firebase in 5 Days — Day 1

Firebase Setup and Authentication

Create a Firebase project, add auth providers, and build sign-up/login/logout flows.

Firebase Project Setup

Install
npm install firebase
src/firebase.js
import { initializeApp } from 'firebase/app';
import { getAuth } from 'firebase/auth';
import { getFirestore } from 'firebase/firestore';

const firebaseConfig = {
  apiKey: import.meta.env.VITE_FIREBASE_API_KEY,
  authDomain: 'your-app.firebaseapp.com',
  projectId: 'your-app-id',
  storageBucket: 'your-app.appspot.com',
  messagingSenderId: '123456789',
  appId: '1:123456789:web:abcdef'
};

const app = initializeApp(firebaseConfig);
export const auth = getAuth(app);
export const db = getFirestore(app);
Auth operations
import { auth } from './firebase';
import {
  createUserWithEmailAndPassword,
  signInWithEmailAndPassword,
  signInWithPopup,
  GoogleAuthProvider,
  signOut,
  onAuthStateChanged
} from 'firebase/auth';

// Sign up
await createUserWithEmailAndPassword(auth, email, password);

// Login
await signInWithEmailAndPassword(auth, email, password);

// Google OAuth
const provider = new GoogleAuthProvider();
await signInWithPopup(auth, provider);

// Logout
await signOut(auth);

// Listen to auth state
onAuthStateChanged(auth, (user) => {
  if (user) console.log('Logged in:', user.uid);
  else console.log('Logged out');
});
📝 Day 1 Exercise
Build Firebase Auth
  1. C
  2. r
  3. e
  4. a
  5. t
  6. e
  7. a
  8. F
  9. i
  10. r
  11. e
  12. b
  13. a
  14. s
  15. e
  16. p
  17. r
  18. o
  19. j
  20. e
  21. c
  22. t
  23. .
  24. E
  25. n
  26. a
  27. b
  28. l
  29. e
  30. e
  31. m
  32. a
  33. i
  34. l
  35. /
  36. p
  37. a
  38. s
  39. s
  40. w
  41. o
  42. r
  43. d
  44. a
  45. n
  46. d
  47. G
  48. o
  49. o
  50. g
  51. l
  52. e
  53. a
  54. u
  55. t
  56. h
  57. i
  58. n
  59. t
  60. h
  61. e
  62. c
  63. o
  64. n
  65. s
  66. o
  67. l
  68. e
  69. .
  70. B
  71. u
  72. i
  73. l
  74. d
  75. l
  76. o
  77. g
  78. i
  79. n
  80. ,
  81. s
  82. i
  83. g
  84. n
  85. -
  86. u
  87. p
  88. ,
  89. a
  90. n
  91. d
  92. l
  93. o
  94. g
  95. o
  96. u
  97. t
  98. f
  99. l
  100. o
  101. w
  102. s
  103. .
  104. D
  105. i
  106. s
  107. p
  108. l
  109. a
  110. y
  111. t
  112. h
  113. e
  114. u
  115. s
  116. e
  117. r
  118. '
  119. s
  120. d
  121. i
  122. s
  123. p
  124. l
  125. a
  126. y
  127. n
  128. a
  129. m
  130. e
  131. a
  132. n
  133. d
  134. p
  135. h
  136. o
  137. t
  138. o
  139. w
  140. h
  141. e
  142. n
  143. l
  144. o
  145. g
  146. g
  147. e
  148. d
  149. i
  150. n
  151. .

Day 1 Summary

  • Firebase console: Authentication → Sign-in methods to enable providers.
  • createUserWithEmailAndPassword, signInWithEmailAndPassword, signOut — the core auth methods.
  • onAuthStateChanged is the auth state listener. Use it to update your app's UI.
  • Store the Firebase config in environment variables. The API key is public-safe but should still not be hardcoded.
Finished this lesson?