multi-user support

This commit is contained in:
2024-01-08 16:32:08 +01:00
parent 9314d78c9c
commit 8a90c58417
9 changed files with 117 additions and 58 deletions

View File

@@ -6,7 +6,7 @@ import clientPromise from './lib/mongodb';
import { BillingLocation } from './lib/db-types';
import { PageFooter } from './ui/PageFooter';
import { auth } from '@/app/lib/auth';
import { redirect } from 'next/navigation';
import { fetchAllLocations } from './lib/locationActions';
const getNextYearMonth = (yearMonth:number) => {
return(yearMonth % 100 === 12 ? yearMonth + 89 : yearMonth + 1);
@@ -14,16 +14,7 @@ const getNextYearMonth = (yearMonth:number) => {
export const Page = async () => {
const session = await auth();
const client = await clientPromise;
const db = client.db("rezije");
const locations = await db.collection<BillingLocation>("lokacije")
.find({})
.sort({ yearMonth: -1, name: 1 }) // sort by yearMonth descending
.limit(20)
.toArray();
const locations = await fetchAllLocations();
// if the database is in it's initial state, show the add location button for the current month
if(locations.length === 0) {
@@ -61,13 +52,6 @@ export const Page = async () => {
})
}
<PageFooter />
<ul>
<li>session.expires = { session?.expires }</li>
<li>session.user.id = { session?.user?.id }</li>
<li>session.user.email = { session?.user?.email }</li>
<li>session.user.name = { session?.user?.name }</li>
<li>session.user.image = { session?.user?.image }</li>
</ul>
</main>
);
}