Search Icon Icon to open search
Last updated Unknown
Status:
Tags:
Links: ReactJS Web Features
ReactJS User Authentication
Server-Side
In firebase.js
have
1
const auth = getAuth ();
Import functions
1
2
3
4
5
6
7
8
9
10
11
// Coder-made functions to create documents to store user info
import {
createProfessorDocument ,
createInstructorDocument
} from "./create.js" ;
//Official Firebase methods used for user authentication
import {
signInWithEmailAndPassword ,
createUserWithEmailAndPassword ,
} from "firebase/auth" ;
Call Firebase functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const signUpProfessor = async (
email ,
password ,
username ,
title ,
description
) => {
let user = undefined ;
await createUserWithEmailAndPassword ( auth , email , password )
. then (( userCredential ) => {
user = userCredential . user ;
user . displayName = username ;
createProfessorDocument ( user , username , title , description );
}) //
. catch (( error ) => {
console . log ( serverError ( error . code , error . message ));
});
return user ;
};
Creating the professor document
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const createProfessorDocument = async (
user ,
userUsername ,
userTitle ,
userDescription
) => {
await setDoc (
doc ( db , `Professors/ ${ user . uid } ` ),
{
email : user . email ,
username : userUsername ,
title : userTitle ,
description : userDescription ,
},
{ merge : true } //add onto already-existing
);
};
Export functions
1
export { signIn , signUpProfessor , signUpInstructor };
Usage for React
Import functions from files
1
2
import * as Auth from "./firebase-files/Auth" ;
import * as Create from "./firebase-files/create" ;
Examples
OnlyProfs
References:
Created:: 2022-03-19 22:40