Structured libs
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
"use server";
|
||||
import { read, write } from "@/app/api/file";
|
||||
import testAuth from "@/lib/server/auth";
|
||||
import { read, write } from "@/lib/server/file";
|
||||
import { NodeJsonTemplate } from "@/lib/server/types";
|
||||
import axios from "axios";
|
||||
import { createHash } from "crypto";
|
||||
import { cookies } from "next/headers";
|
||||
@@ -20,7 +22,7 @@ export async function getSession(): Promise<
|
||||
const tokens: Record<string, string> = await read(
|
||||
() => ({}),
|
||||
"data",
|
||||
"sessions.json"
|
||||
"sessions.json",
|
||||
);
|
||||
|
||||
const tokenHash = createHash("sha256").update(accessToken).digest("hex");
|
||||
@@ -36,7 +38,7 @@ export async function getSession(): Promise<
|
||||
|
||||
// Test the token
|
||||
const users = Object.keys(
|
||||
await read<Users>(() => ({}), "data", "users.json")
|
||||
await read<Users>(() => ({}), "data", "users.json"),
|
||||
);
|
||||
|
||||
if (!users.includes(String(userId))) {
|
||||
@@ -44,8 +46,10 @@ export async function getSession(): Promise<
|
||||
await write(
|
||||
{ [userId]: { roles: ["admin"] } } as Users, // First user is always an admin
|
||||
"data",
|
||||
"users.json"
|
||||
"users.json",
|
||||
);
|
||||
const { key } = await read(NodeJsonTemplate, "data", "node.json");
|
||||
console.log(`Node key: ${key}\ncwd: ${process.cwd()}`);
|
||||
} else {
|
||||
throw new Error("Invalid user");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user