Skip to content

Commit

Permalink
registro
Browse files Browse the repository at this point in the history
  • Loading branch information
Arejula11 committed Apr 4, 2024
1 parent 1c902b1 commit 5f8c55f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion playbeat/src/globalState/globalUrl.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const Global ={
url: "https://playbeat.uksouth.cloudapp.azure.com:3000/"
url: "http://playbeat.uksouth.cloudapp.azure.com:3000/"
};
10 changes: 3 additions & 7 deletions playbeat/src/pages/register.astro
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,9 @@ if (Astro.request.method === "POST") {
// Do something with the data
const hasErrors = Object.values(errors).some(msg => msg)
if (!hasErrors) {
const response = await registerUser({name, email, password});
console.log(`Response: ${response}`)
if (response && response.ok == true) {
console.log("Registrado");
const data = await response.json();
const token = data.token;
Astro.cookies.set("token", token);
const response = await registerUser({nombreUsuario: name, email, contrasegna: password});
if (response && response.status === 201) {
Astro.cookies.set("token", data);
return Astro.redirect("/");
} else {
errors.peticion = "Error al registrar, intentelo de nuevo";
Expand Down
8 changes: 3 additions & 5 deletions playbeat/src/utils/register.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Global } from "@/globalState/globalUrl.js";
import axios from 'axios';

async function registerUser(data: { name: any; email: any; password: any; }) {
async function registerUser(data: { nombreUsuario: any; email: any; contrasegna: any; }) {
try {
console.log("Sending request with data:", data);
const response = await axios.post(Global.url + "auth/signup", data);

console.log("Response:", response.data);
const response = await axios.post(Global.url + "auth/signup", data);

return response.data;
return response;
} catch (error) {
console.error("Error registering user:", error);
throw error;
Expand Down

0 comments on commit 5f8c55f

Please sign in to comment.