Skip to content

Commit

Permalink
create user api
Browse files Browse the repository at this point in the history
  • Loading branch information
TI JONNY committed Sep 13, 2024
1 parent 917d209 commit c401b61
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 43 deletions.
2 changes: 0 additions & 2 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ export const userUpdate = updateUserData(corsMiddleware);
export const addPointsStud = addPointsStudent(corsMiddleware);


export const addPointsStud = addPointsStudent(corsMiddleware)

export const helloWorld = functions.https.onRequest((request, response) => {
corsMiddleware(request, response, () => {
response.send("Hello from Firebase!");
Expand Down
7 changes: 3 additions & 4 deletions src/controller/classroom/createClassroom.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { firestore } from "../../config/firebase"
import { collection } from "@firebase/firestore"
import { addDoc } from "@firebase/firestore"
import { addDoc, collection } from "@firebase/firestore";
import { firestore } from "../../config/firebase";


const handleSubmitClassroom = (body, history) => {
const ref = collection(firestore, "classroom");

let data = body

try {
Expand All @@ -16,4 +14,5 @@ const handleSubmitClassroom = (body, history) => {
}
}


export default handleSubmitClassroom
92 changes: 60 additions & 32 deletions src/controller/user/createUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,74 @@
// import { addDoc } from "@firebase/firestore";
// import Swal from "sweetalert2";

// ====================================================================================
import axios from 'axios';
import Swal from "sweetalert2";
import api from "../../services/api";

export const CreateUserRequest = async (body) => {
return await api.post("/userCreate", body).then((data) => {
Swal.fire({
title: "Sucesso!",
text: "Usuário criado com sucesso!",
icon: "success",
confirmButtonText: "Ok",
});
}).catch((error) => {
console.error("Erro ao criar usuário", error);
Swal.fire({
title: "Erro!",
text: "Erro",
icon: "error",
confirmButtonText: "Ok",
});
throw error;
})
}


export async function createUser(data) {
try {
await axios.post(`https://us-central1-br-ipti-visao.cloudfunctions.net/userCreate`);
const userData = {
name: data.name,
role: data.role,
email: data.email,
};

CreateUserRequest(userData)


console.log("Usuário criado com sucesso");
} catch (err) {
console.error("Erro ao criar usuário", err);
throw err;
console.error("Erro ao criar usuário", err);
throw err;
}
}
// ====================================================================================

// export function createUser(data) {
// // Create the user with email and password
// createUserWithEmailAndPassword(auth, data.email, data.password)
// .then((userCredential) => {
// // User created successfully
// const user = userCredential.user;

// const userData = {
// name: data.name,
// role: data.role,
// email: user.email,
// uid: user.uid,
// };

// const ref = collection(firestore, "userData");
// addDoc(ref, userData);
// Swal.fire({
// title: "Sucesso!",
// text: "Usuário criado com sucesso!",
// icon: "success",
// confirmButtonText: "Ok",
// });

// })
// .catch((error) => {
// // Handle errors
// console.error("Error creating user:", error.message);
// Create the user with email and password
// createUserWithEmailAndPassword(auth, data.email, data.password)
// .then((userCredential) => {
// // User created successfully
// const user = userCredential.user;

// const userData = {
// name: data.name,
// role: data.role,
// email: user.email,
// uid: user.uid,
// };

// const ref = collection(firestore, "userData");
// addDoc(ref, userData);
// Swal.fire({
// title: "Sucesso!",
// text: "Usuário criado com sucesso!",
// icon: "success",
// confirmButtonText: "Ok",
// });
// }

// })
// .catch((error) => {
// // Handle errors
// console.error("Error creating user:", error.message);
// });
6 changes: 5 additions & 1 deletion src/services/api.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import axios from "axios";
import { getToken } from "./auth";





const api = axios.create({
  baseURL"https://apitag.azurewebsites.net/"
  baseURL"https://us-central1-br-ipti-visao.cloudfunctions.net/"
});

api.interceptors.request.use(async config => {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4246,10 +4246,10 @@ caniuse-api@^3.0.0:
lodash.memoize "^4.1.2"
lodash.uniq "^4.5.0"

caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001010, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001517:
version "1.0.30001524"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001524.tgz"
integrity sha512-Jj917pJtYg9HSJBF95HVX3Cdr89JUyLT4IZ8SvM5aDRni95swKgYi3TgYLH5hnGfPE/U1dg6IfZ50UsIlLkwSA==
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001010, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001517, caniuse-lite@^1.0.30001651:
version "1.0.30001651"
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001651.tgz"
integrity sha512-9Cf+Xv1jJNe1xPZLGuUXLNkE1BoDkqRqYyFJ9TDYSqhduqA4hu4oR9HluGoWYQC/aj8WHjsGVV+bwkh0+tegRg==

canvg@^3.0.6:
version "3.0.10"
Expand Down

0 comments on commit c401b61

Please sign in to comment.