refactor: enhance password change page with improved UI and functionality
- Updated the layout and styling of the password change page for a more modern and user-friendly experience. - Integrated new icons and visual elements to enhance the overall design and accessibility. - Improved form handling with better loading states and error messages for user feedback. - Added security tips and password requirements to guide users during the password change process.
This commit is contained in:
2
packages/backend/convex/_generated/api.d.ts
vendored
2
packages/backend/convex/_generated/api.d.ts
vendored
@@ -15,6 +15,7 @@ import type * as actions_smtp from "../actions/smtp.js";
|
||||
import type * as actions_utils_nodeCrypto from "../actions/utils/nodeCrypto.js";
|
||||
import type * as atestadosLicencas from "../atestadosLicencas.js";
|
||||
import type * as ausencias from "../ausencias.js";
|
||||
import type * as autenticacao from "../autenticacao.js";
|
||||
import type * as auth from "../auth.js";
|
||||
import type * as auth_utils from "../auth/utils.js";
|
||||
import type * as chamados from "../chamados.js";
|
||||
@@ -63,6 +64,7 @@ declare const fullApi: ApiFromModules<{
|
||||
"actions/utils/nodeCrypto": typeof actions_utils_nodeCrypto;
|
||||
atestadosLicencas: typeof atestadosLicencas;
|
||||
ausencias: typeof ausencias;
|
||||
autenticacao: typeof autenticacao;
|
||||
auth: typeof auth;
|
||||
"auth/utils": typeof auth_utils;
|
||||
chamados: typeof chamados;
|
||||
|
||||
72
packages/backend/convex/autenticacao.ts
Normal file
72
packages/backend/convex/autenticacao.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { mutation } from './_generated/server';
|
||||
import { v } from 'convex/values';
|
||||
import { updatePassword } from './auth';
|
||||
import { authComponent } from './auth';
|
||||
|
||||
/**
|
||||
* Alterar senha do usuário autenticado
|
||||
*/
|
||||
export const alterarSenha = mutation({
|
||||
args: {
|
||||
token: v.string(), // Token não é usado, mas mantido para compatibilidade
|
||||
senhaAtual: v.string(),
|
||||
novaSenha: v.string()
|
||||
},
|
||||
returns: v.union(
|
||||
v.object({ sucesso: v.literal(true) }),
|
||||
v.object({ sucesso: v.literal(false), erro: v.string() })
|
||||
),
|
||||
handler: async (ctx, args) => {
|
||||
try {
|
||||
// Verificar se o usuário está autenticado
|
||||
const authUser = await authComponent.safeGetAuthUser(ctx);
|
||||
if (!authUser) {
|
||||
return {
|
||||
sucesso: false as const,
|
||||
erro: 'Usuário não autenticado'
|
||||
};
|
||||
}
|
||||
|
||||
// Validar que a nova senha não está vazia
|
||||
if (!args.novaSenha || args.novaSenha.trim().length === 0) {
|
||||
return {
|
||||
sucesso: false as const,
|
||||
erro: 'A nova senha não pode estar vazia'
|
||||
};
|
||||
}
|
||||
|
||||
// Chamar a função de atualização de senha
|
||||
await updatePassword(ctx, {
|
||||
currentPassword: args.senhaAtual,
|
||||
newPassword: args.novaSenha
|
||||
});
|
||||
|
||||
return {
|
||||
sucesso: true as const
|
||||
};
|
||||
} catch (error: any) {
|
||||
// Capturar erros específicos do Better Auth
|
||||
let mensagemErro = 'Erro ao alterar senha';
|
||||
|
||||
if (error?.message) {
|
||||
mensagemErro = error.message;
|
||||
} else if (typeof error === 'string') {
|
||||
mensagemErro = error;
|
||||
}
|
||||
|
||||
// Mensagens de erro mais amigáveis
|
||||
if (mensagemErro.toLowerCase().includes('password') ||
|
||||
mensagemErro.toLowerCase().includes('senha') ||
|
||||
mensagemErro.toLowerCase().includes('incorrect') ||
|
||||
mensagemErro.toLowerCase().includes('incorreta')) {
|
||||
mensagemErro = 'Senha atual incorreta';
|
||||
}
|
||||
|
||||
return {
|
||||
sucesso: false as const,
|
||||
erro: mensagemErro
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user