feat: auth redirect

This commit is contained in:
trev 2025-03-18 17:46:54 -04:00
parent 86b74e0ebc
commit be0981f7b7
2 changed files with 6 additions and 2 deletions

View File

@ -7,6 +7,7 @@
import { toast } from 'svelte-sonner';
import Button from '$lib/ui/Button.svelte';
import Input from '$lib/ui/Input.svelte';
import { page } from '$app/state';
let tab = $state('login');
</script>
@ -41,6 +42,7 @@
const formData = new FormData(e.target as HTMLFormElement);
const username = formData.get('login-username')?.toString();
const password = formData.get('login-password')?.toString();
const redir = page.url.searchParams.get('redir') || '/';
try {
const response = await AuthClient.login({
@ -49,7 +51,7 @@
});
if (response.token && username) {
goto('/');
goto(redir);
}
} catch (err) {
const error = ConnectError.from(err);

View File

@ -6,6 +6,7 @@ import (
"fmt"
"log"
"net/http"
"net/url"
"strconv"
"strings"
@ -62,7 +63,8 @@ func WithAuthRedirect(next http.Handler, key string) http.Handler {
}
// Redirect if not authenticated
http.Redirect(w, r, "/auth", http.StatusFound)
pathRedir := url.QueryEscape(r.URL.Path)
http.Redirect(w, r, fmt.Sprintf("/auth?redir=%s", pathRedir), http.StatusFound)
}
})
}