New feature on the account creation:
It automatically stores who created the code and adds the registered user to a group administrated by that creator
This commit is contained in:
@@ -5,6 +5,7 @@ import {sessionOptions} from "@/lib/session";
|
||||
import {withIronSessionApiRoute} from "iron-session/next";
|
||||
import {getFirestore, doc, setDoc, query, collection, where, getDocs} from "firebase/firestore";
|
||||
import {DemographicInformation, Type} from "@/interfaces/user";
|
||||
import {addUserToGroupOnCreation} from "@/utils/registration";
|
||||
|
||||
const auth = getAuth(app);
|
||||
const db = getFirestore(app);
|
||||
@@ -36,7 +37,7 @@ async function login(req: NextApiRequest, res: NextApiResponse) {
|
||||
return;
|
||||
}
|
||||
|
||||
const codeData = codeDocs[0].data() as {code: string; type: Type};
|
||||
const codeData = codeDocs[0].data() as {code: string; type: Type; creator: string};
|
||||
|
||||
createUserWithEmailAndPassword(auth, email, password)
|
||||
.then(async (userCredentials) => {
|
||||
@@ -55,6 +56,7 @@ async function login(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
await setDoc(doc(db, "users", userId), user);
|
||||
await setDoc(codeDocs[0].ref, {userId: userId}, {merge: true});
|
||||
await addUserToGroupOnCreation(userId, codeData.type, codeData.creator);
|
||||
|
||||
req.session.user = {...user, id: userId};
|
||||
await req.session.save();
|
||||
|
||||
Reference in New Issue
Block a user