Vue.component('register-form', { template: `

Cadastre-se

Cadastrar
Já tem uma conta? Faça login
`, data() { return { tipodecarga: '', email: '', senha: '', confirmarSenha: '', loading: false // Para controle de loading } }, methods: { async register() { // Verificar se as senhas são iguais if (this.senha !== this.confirmarSenha) { Swal.fire({ icon: 'error', title: 'Erro ao cadastrar!', text: 'As senhas não coincidem.', confirmButtonText: 'Tente novamente', customClass: { confirmButton: 'swal-button-center custom-button' } }); return; // Interromper o processo de cadastro } this.loading = true; // Ativar loading try { const response = await axios.post('https://api-pi4-323375316797.us-east4.run.app/api/novoUsuario', { nome: this.tipodecarga, email: this.email, senha: this.senha, }); Swal.fire({ icon: 'success', title: 'Cadastro realizado com sucesso!', text: 'Você já pode fazer login.', confirmButtonText: 'Ok', customClass: { confirmButton: 'swal-button-center' } }); // Limpar os campos após o cadastro this.tipodecarga = ''; this.email = ''; this.senha = ''; this.confirmarSenha = ''; // Emitir evento para mudar a visualização, se necessário this.$emit('switch-view', 'login-form'); } catch (error) { const errorMessage = error.response?.data?.error || 'Ocorreu um erro ao tentar cadastrar.'; console.error('Erro ao cadastrar', errorMessage); Swal.fire({ icon: 'error', title: 'Erro ao cadastrar', text: errorMessage, confirmButtonText: 'Tente novamente', customClass: { confirmButton: 'swal-button-center custom-button' } }); } finally { this.loading = false; // Desativar loading } } } });