base con autenticacion, registro, modulo encuestas
This commit is contained in:
17
apps/web/feactures/auth/actions/login-action.ts
Normal file
17
apps/web/feactures/auth/actions/login-action.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
'use server';
|
||||
import { safeFetchApi } from '@/lib';
|
||||
import { loginResponseSchema, UserFormValue } from '../schemas/login';
|
||||
|
||||
export const SignInAction = async (payload: UserFormValue) => {
|
||||
const [error, data] = await safeFetchApi(
|
||||
loginResponseSchema,
|
||||
'/auth/sign-in',
|
||||
'POST',
|
||||
payload,
|
||||
);
|
||||
if (error) {
|
||||
return error;
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
};
|
||||
20
apps/web/feactures/auth/actions/refresh-token-action.ts
Normal file
20
apps/web/feactures/auth/actions/refresh-token-action.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
'use server';
|
||||
import { safeFetchApi } from '@/lib';
|
||||
import {
|
||||
RefreshTokenResponseSchema,
|
||||
RefreshTokenValue,
|
||||
} from '../schemas/refreshToken';
|
||||
|
||||
export const resfreshTokenAction = async (refreshToken: RefreshTokenValue) => {
|
||||
const [error, data] = await safeFetchApi(
|
||||
RefreshTokenResponseSchema,
|
||||
'/auth/refreshToken',
|
||||
'POST',
|
||||
refreshToken,
|
||||
);
|
||||
if (error) {
|
||||
console.error('Error:', error);
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
};
|
||||
27
apps/web/feactures/auth/actions/register.ts
Normal file
27
apps/web/feactures/auth/actions/register.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
'use server';
|
||||
import { safeFetchApi } from '@/lib/fetch.api';
|
||||
import { createUserValue, UsersMutate } from '../schemas/register';
|
||||
|
||||
export const registerUserAction = async (payload: createUserValue) => {
|
||||
const { confirmPassword, ...payloadWithoutId } = payload;
|
||||
|
||||
const [error, data] = await safeFetchApi(
|
||||
UsersMutate,
|
||||
'/auth/sing-up',
|
||||
'POST',
|
||||
payloadWithoutId,
|
||||
);
|
||||
|
||||
if (error) {
|
||||
// console.error(error);
|
||||
if (error.message === 'Username already exists') {
|
||||
throw new Error('Ese usuario ya existe');
|
||||
}
|
||||
if (error.message === 'Email already exists') {
|
||||
throw new Error('Ese correo ya está en uso');
|
||||
}
|
||||
throw new Error('Error al crear el usuario');
|
||||
}
|
||||
|
||||
return payloadWithoutId;
|
||||
};
|
||||
Reference in New Issue
Block a user