mirror of
https://github.com/emailerfacu-spec/minix-front.git
synced 2026-04-01 13:10:44 -03:00
fix: ahora no se va a la pagina de login cuando creas el usuario
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
import Spinner from '../ui/spinner/spinner.svelte';
|
||||
import { register } from '@/hooks/register';
|
||||
import type { RegisterDto } from '../../../types';
|
||||
import { invalidate } from '$app/navigation';
|
||||
|
||||
interface Prop {
|
||||
open: boolean;
|
||||
@@ -29,9 +30,18 @@
|
||||
cargando = true;
|
||||
error = '';
|
||||
|
||||
await register(e, dto, () => {
|
||||
error = 'Error al registrar el usuario';
|
||||
});
|
||||
await register(
|
||||
e,
|
||||
dto,
|
||||
() => {
|
||||
error = 'Error al registrar el usuario';
|
||||
},
|
||||
true
|
||||
);
|
||||
if (error == '') {
|
||||
invalidate('admin:load');
|
||||
open = false;
|
||||
}
|
||||
|
||||
cargando = false;
|
||||
}
|
||||
@@ -57,11 +67,7 @@
|
||||
</InputGroup>
|
||||
|
||||
<InputGroup>
|
||||
<InputGroupInput
|
||||
type="email"
|
||||
disabled={cargando}
|
||||
bind:value={dto.email}
|
||||
/>
|
||||
<InputGroupInput type="email" disabled={cargando} bind:value={dto.email} />
|
||||
<InputGroupAddon>Email</InputGroupAddon>
|
||||
</InputGroup>
|
||||
|
||||
@@ -71,11 +77,7 @@
|
||||
</InputGroup>
|
||||
|
||||
<InputGroup>
|
||||
<InputGroupInput
|
||||
type="password"
|
||||
disabled={cargando}
|
||||
bind:value={dto.password}
|
||||
/>
|
||||
<InputGroupInput type="password" disabled={cargando} bind:value={dto.password} />
|
||||
<InputGroupAddon>Contraseña</InputGroupAddon>
|
||||
</InputGroup>
|
||||
|
||||
@@ -90,11 +92,7 @@
|
||||
{/if}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
variant="secondary"
|
||||
disabled={cargando}
|
||||
onclick={() => (open = false)}
|
||||
>
|
||||
<Button variant="secondary" disabled={cargando} onclick={() => (open = false)}>
|
||||
Cancelar
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
import { apiBase } from '@/stores/url';
|
||||
import { goto } from '$app/navigation';
|
||||
import type { RegisterDto } from '../../types';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
export async function register(e: SubmitEvent, dto: RegisterDto, callbackfn: () => void) {
|
||||
export async function register(
|
||||
e: SubmitEvent,
|
||||
dto: RegisterDto,
|
||||
callbackfn: () => void,
|
||||
admin: boolean = false
|
||||
) {
|
||||
e.preventDefault();
|
||||
if (
|
||||
dto.password == '' ||
|
||||
@@ -12,13 +18,7 @@ export async function register(e: SubmitEvent, dto: RegisterDto, callbackfn: ()
|
||||
)
|
||||
return;
|
||||
try {
|
||||
const { subscribe } = apiBase;
|
||||
let baseUrl: string = '';
|
||||
|
||||
subscribe((value) => {
|
||||
baseUrl = value;
|
||||
})();
|
||||
const req = await fetch(baseUrl + '/api/auth/register', {
|
||||
const req = await fetch(get(apiBase) + '/api/auth/register', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
@@ -27,7 +27,7 @@ export async function register(e: SubmitEvent, dto: RegisterDto, callbackfn: ()
|
||||
});
|
||||
if (req.ok) {
|
||||
const data = await req.json();
|
||||
goto('/login?msg=' + data.message);
|
||||
if (!admin) goto('/login?msg=' + data.message);
|
||||
} else {
|
||||
callbackfn();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user