Lashtw commited on
Commit
90f7646
·
verified ·
1 Parent(s): c174672

Upload 9 files

Browse files
Files changed (2) hide show
  1. src/services/auth.js +17 -33
  2. src/views/InstructorView.js +0 -0
src/services/auth.js CHANGED
@@ -1,5 +1,9 @@
1
- import { auth, googleProvider, db } from "./firebase.js";
2
- import { signInWithPopup, signInWithRedirect, signOut, getRedirectResult, setPersistence, browserLocalPersistence } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-auth.js";
 
 
 
 
3
  import {
4
  doc,
5
  getDoc,
@@ -16,53 +20,33 @@ const INSTRUCTORS_COLLECTION = "instructors";
16
  const SUPER_ADMIN_EMAIL = "t92206@gmail.com";
17
 
18
  /**
19
- * Sign in with Google
20
  */
21
- export async function signInWithGoogle() {
22
  try {
23
- await setPersistence(auth, browserLocalPersistence);
24
- const result = await signInWithPopup(auth, googleProvider);
25
  return result.user;
26
  } catch (error) {
27
- console.error("Google Sign-In Error:", error);
28
  throw error;
29
  }
30
  }
31
 
32
  /**
33
- * Sign in with Google (Redirect Mode)
34
- * Use this if popup is blocked
35
  */
36
- export async function signInWithGoogleRedirect() {
37
  try {
38
- await setPersistence(auth, browserLocalPersistence);
39
- await signInWithRedirect(auth, googleProvider);
40
- // Does not return value, page will redirect
41
  } catch (error) {
42
- console.error("Google Redirect Error:", error);
43
  throw error;
44
  }
45
  }
46
 
47
- /**
48
- * Check for Redirect Result
49
- * Call this on page load to handle redirect callback
50
- */
51
- export async function handleRedirectResult() {
52
- console.log("Checking for redirect result...");
53
- try {
54
- const result = await getRedirectResult(auth);
55
- if (result && result.user) {
56
- console.log("Redirect Sign-In Successful:", result.user.email);
57
- return result.user;
58
- } else {
59
- console.log("No redirect result found.");
60
- }
61
- } catch (error) {
62
- console.error("Redirect Result Error:", error);
63
- }
64
- return null;
65
- }
66
 
67
  /**
68
  * Sign out
 
1
+ import { auth, db } from "./firebase.js";
2
+ import {
3
+ signInWithEmailAndPassword,
4
+ createUserWithEmailAndPassword,
5
+ signOut
6
+ } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-auth.js";
7
  import {
8
  doc,
9
  getDoc,
 
20
  const SUPER_ADMIN_EMAIL = "t92206@gmail.com";
21
 
22
  /**
23
+ * Sign in with Email/Password
24
  */
25
+ export async function loginWithEmail(email, password) {
26
  try {
27
+ const result = await signInWithEmailAndPassword(auth, email, password);
 
28
  return result.user;
29
  } catch (error) {
30
+ console.error("Login Error:", error);
31
  throw error;
32
  }
33
  }
34
 
35
  /**
36
+ * Register with Email/Password
37
+ * (Used for new instructors to create their auth account matching their whitelisted email)
38
  */
39
+ export async function registerWithEmail(email, password) {
40
  try {
41
+ const result = await createUserWithEmailAndPassword(auth, email, password);
42
+ return result.user;
 
43
  } catch (error) {
44
+ console.error("Register Error:", error);
45
  throw error;
46
  }
47
  }
48
 
49
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  /**
52
  * Sign out
src/views/InstructorView.js CHANGED
The diff for this file is too large to render. See raw diff