adds oauth support

This commit is contained in:
Christian Beutel
2024-03-29 13:13:23 +01:00
parent 28c6261e94
commit 033343e684
15 changed files with 226 additions and 12 deletions

View File

@@ -1,6 +1,5 @@
<script lang="ts">
import type { SummitLog } from "$lib/models/summit_log";
import { parse } from "date-fns";
import { _ } from "svelte-i18n";
import Dropdown, { type DropdownItem } from "../base/dropdown.svelte";
@@ -16,10 +15,11 @@
<div class="p-4 my-2 border border-input-border rounded-xl">
<div class="flex justify-between items-center mb-2">
<h5 class="font-medium mr-2">
{parse(log.date, "yyyy-MM-dd", new Date()).toLocaleDateString(
undefined,
{ month: "2-digit", day: "2-digit", year: "numeric" },
)}
{new Date(log.date).toLocaleDateString(undefined, {
month: "2-digit",
day: "2-digit",
year: "numeric",
})}
</h5>
{#if mode == "edit"}

View File

@@ -89,6 +89,7 @@
"no-results": "Keine Ergebnisse gefunden",
"not-a-valid-email-address": "Keine gültige Email-Adresse",
"not-completed": "Nicht abgeschlossen",
"or": "oder",
"password": "Passwort",
"photos": "Fotos",
"pick-a-trail": "Route auswählen",

View File

@@ -89,6 +89,7 @@
"no-results": "No results found",
"not-a-valid-email-address": "Not a valid email address",
"not-completed": "Not completed",
"or": "or",
"password": "Password",
"photos": "Photos",
"pick-a-trail": "Pick a trail",

View File

@@ -89,6 +89,7 @@
"no-results": "Pas de résultat",
"not-a-valid-email-address": "Adresse email invalide",
"not-completed": "Pas terminé",
"or": "ou",
"password": "Mot de passe",
"photos": "Photos",
"pick-a-trail": "Choisir un itinéraire",

View File

@@ -89,6 +89,7 @@
"no-results": "Geen resultaten gevonden",
"not-a-valid-email-address": "Geen geldig e-mail adres",
"not-completed": "Niet voltooid",
"or": "of",
"password": "Wachtwoord",
"photos": "Foto's",
"pick-a-trail": "Kies een route",

View File

@@ -89,6 +89,7 @@
"no-results": "Brak wyników",
"not-a-valid-email-address": "Nieprawidłowy adres email",
"not-completed": "Nie dokończono",
"or": "lub",
"password": "Hasło",
"photos": "Zdjęcia",
"pick-a-trail": "Wybierz ścieżkę",

View File

@@ -89,6 +89,7 @@
"no-results": "Nenhum resultado encontrado",
"not-a-valid-email-address": "Não um endereço de e-mail válido",
"not-completed": "Não preenchido",
"or": "ou",
"password": "Senha",
"photos": "Fotos",
"pick-a-trail": "Escolha uma trilha",

View File

@@ -1,5 +1,5 @@
import { pb } from "$lib/pocketbase";
import { ClientResponseError } from "pocketbase";
import { ClientResponseError, type AuthMethodsList } from "pocketbase";
import { writable, type Writable } from "svelte/store";
export type User = {
@@ -30,6 +30,20 @@ export async function users_create(user: User) {
}
export async function users_auth_methods(f: (url: RequestInfo | URL, config?: RequestInit) => Promise<Response> = fetch): Promise<AuthMethodsList> {
const r = await f('/api/v1/auth/oauth', {
method: 'GET',
})
if (r.ok) {
return await r.json()
} else {
throw new ClientResponseError(await r.json())
}
}
export async function login(user: User) {
const r = await fetch('/api/v1/auth/login', {
method: 'POST',
@@ -44,6 +58,23 @@ export async function login(user: User) {
}
export async function oauth_login(data: { name: string, code: string, codeVerifier: string }) {
const r = await fetch('/api/v1/auth/oauth', {
method: 'POST',
body: JSON.stringify(data)
})
console.log(r);
if (r.ok) {
pb.authStore.loadFromCookie(document.cookie)
} else {
throw new ClientResponseError(await r.json())
}
}
export async function logout() {
pb.authStore.clear();
}

View File

@@ -1,6 +1,7 @@
const privateRoutes = [
"/profile",
"/lists",
"/trail/edit/new",
]
export function isRouteProtected(path: string) {