adds oauth support
This commit is contained in:
@@ -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"}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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ę",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const privateRoutes = [
|
||||
"/profile",
|
||||
"/lists",
|
||||
"/trail/edit/new",
|
||||
]
|
||||
|
||||
export function isRouteProtected(path: string) {
|
||||
|
||||
Reference in New Issue
Block a user