Require sign-in for places
Deploy with Docker Compose / deploy (push) Successful in 56s

Gate the places query behind an authenticated user so the list is no
longer public, and relax the place mutations from admin-only to any
signed-in user. Hide the Places tab and skip the fetch entirely for
anonymous visitors.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UKvnE448c1FeepmxZkTezz
This commit is contained in:
2026-09-14 19:58:43 +01:00
co-authored by Claude Opus 5
parent fe6fc02b6b
commit ebb28532c3
3 changed files with 33 additions and 22 deletions
+9 -6
View File
@@ -15,8 +15,8 @@ import (
// CreatePlace is the resolver for the createPlace field.
func (r *mutationResolver) CreatePlace(ctx context.Context, input model.CreatePlaceInput) (*models.Place, error) {
if !IsAdminFromCtx(ctx) {
return nil, fmt.Errorf("admin access required")
if _, ok := UserIDFromCtx(ctx); !ok {
return nil, fmt.Errorf("authentication required")
}
place := models.Place{
Title: input.Title,
@@ -40,8 +40,8 @@ func (r *mutationResolver) CreatePlace(ctx context.Context, input model.CreatePl
// UpdatePlace is the resolver for the updatePlace field.
func (r *mutationResolver) UpdatePlace(ctx context.Context, id int, input model.UpdatePlaceInput) (*models.Place, error) {
if !IsAdminFromCtx(ctx) {
return nil, fmt.Errorf("admin access required")
if _, ok := UserIDFromCtx(ctx); !ok {
return nil, fmt.Errorf("authentication required")
}
var place models.Place
if err := r.Store.DB.First(&place, id).Error; err != nil {
@@ -79,8 +79,8 @@ func (r *mutationResolver) UpdatePlace(ctx context.Context, id int, input model.
// DeletePlace is the resolver for the deletePlace field.
func (r *mutationResolver) DeletePlace(ctx context.Context, id int) (*models.Place, error) {
if !IsAdminFromCtx(ctx) {
return nil, fmt.Errorf("admin access required")
if _, ok := UserIDFromCtx(ctx); !ok {
return nil, fmt.Errorf("authentication required")
}
var place models.Place
if err := r.Store.DB.First(&place, id).Error; err != nil {
@@ -99,6 +99,9 @@ func (r *placeResolver) ID(ctx context.Context, obj *models.Place) (int, error)
// Places is the resolver for the places field.
func (r *queryResolver) Places(ctx context.Context) ([]*models.Place, error) {
if _, ok := UserIDFromCtx(ctx); !ok {
return nil, fmt.Errorf("authentication required")
}
var places []models.Place
if err := r.Store.DB.Order("done ASC, priority DESC, created_at DESC").Find(&places).Error; err != nil {
return nil, err
+12 -8
View File
@@ -1,5 +1,5 @@
<script setup>
import { ref, computed } from "vue";
import { ref, computed, watch } from "vue";
import Slideshow from "@/components/util/Slideshow.vue";
import Modal from "@/components/util/Modal.vue";
import PlacesTable from "./PlacesTable.vue";
@@ -8,16 +8,20 @@ import { useAuthStore } from "@/stores/auth";
const images = [{ url: "/img/memes/pidgeon.gif", comment: "鸟" }];
const tabs = [
const auth = useAuthStore();
const loggedIn = computed(() => auth.loggedIn);
const tabs = computed(() => [
{ id: "collage", label: "鸟" },
{ id: "places", label: "Places" },
];
...(loggedIn.value ? [{ id: "places", label: "Places" }] : []),
]);
const activeTab = ref("collage");
const showAdd = ref(false);
const auth = useAuthStore();
const isAdmin = computed(() => !!auth.user?.admin);
watch(loggedIn, (isIn) => {
if (!isIn && activeTab.value === "places") activeTab.value = "collage";
});
</script>
<template>
@@ -34,7 +38,7 @@ const isAdmin = computed(() => !!auth.user?.admin);
</button>
<div class="tab-spacer" />
<button
v-if="isAdmin && activeTab === 'places'"
v-if="loggedIn && activeTab === 'places'"
class="tab add-btn"
title="Add a place / thing to do"
@click="showAdd = true"
@@ -45,7 +49,7 @@ const isAdmin = computed(() => !!auth.user?.admin);
<div class="tab-body">
<Slideshow v-if="activeTab === 'collage'" :images="images" />
<PlacesTable v-else />
<PlacesTable v-else-if="loggedIn" />
</div>
<Modal v-model="showAdd">
+12 -8
View File
@@ -1,18 +1,22 @@
<script setup>
import { computed, onMounted } from "vue";
import { computed, onMounted, watch } from "vue";
import { usePlacesStore } from "@/stores/places";
import { useAuthStore } from "@/stores/auth";
const places = usePlacesStore();
const auth = useAuthStore();
const isAdmin = computed(() => !!auth.user?.admin);
const loggedIn = computed(() => auth.loggedIn);
onMounted(() => {
if (!places.loaded && !places.loading) places.fetch();
if (loggedIn.value && !places.loaded && !places.loading) places.fetch();
});
watch(loggedIn, (isIn) => {
if (isIn && !places.loaded && !places.loading) places.fetch();
});
async function toggleDone(place) {
if (!isAdmin.value) return;
if (!loggedIn.value) return;
try {
await places.toggleDone(place);
} catch (err) {
@@ -21,7 +25,7 @@ async function toggleDone(place) {
}
async function remove(place) {
if (!isAdmin.value) return;
if (!loggedIn.value) return;
if (!confirm(`Delete "${place.title}"?`)) return;
try {
await places.remove(place.id);
@@ -49,7 +53,7 @@ async function remove(place) {
<th class="col-loc">Where</th>
<th class="col-cat">Type</th>
<th class="col-cost">Cost</th>
<th v-if="isAdmin" class="col-act"></th>
<th v-if="loggedIn" class="col-act"></th>
</tr>
</thead>
<tbody>
@@ -61,7 +65,7 @@ async function remove(place) {
<td>
<div class="title-cell">
<button
v-if="isAdmin"
v-if="loggedIn"
class="done-toggle"
:title="place.done ? 'Mark as pending' : 'Mark as done'"
@click="toggleDone(place)"
@@ -75,7 +79,7 @@ async function remove(place) {
<td class="col-loc">{{ place.location || "—" }}</td>
<td class="col-cat">{{ place.category || "—" }}</td>
<td class="col-cost">{{ place.cost || "—" }}</td>
<td v-if="isAdmin" class="col-act">
<td v-if="loggedIn" class="col-act">
<button class="row-action" @click="remove(place)" title="Delete">
×
</button>