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