Add some stub user stuff

This commit is contained in:
2026-01-03 17:06:54 -06:00
parent c926f15aab
commit e136c07928
3 changed files with 44 additions and 1 deletions

View File

@@ -59,6 +59,29 @@ const routes: Route[] = [
};
},
},
{
path: "/whoami",
methods: ["GET"],
handler: async (_call: Call): Promise<Result> => {
const me = services.session.getUser();
const template = `
<html>
<head></head>
<body>
{{ me }}
</body>
</html>
`;
const result = nunjucks.renderString(template, { me });
return {
code: httpCodes.success.OK,
contentType: contentTypes.text.html,
result,
};
},
},
{
path: "/ok",
methods: ["GET", "POST", "PUT"],

View File

@@ -3,6 +3,7 @@
import { AuthService, InMemoryAuthStore } from "../auth";
import { config } from "../config";
import { getLogs, log } from "../logging";
import { AnonymousUser, anonymousUser, type User } from "../user";
//const database = Client({
@@ -27,16 +28,24 @@ const misc = {
},
};
const session = {
getUser: (): User => {
return anonymousUser;
},
};
// Initialize auth with in-memory store
const authStore = new InMemoryAuthStore();
const auth = new AuthService(authStore);
// Keep this asciibetically sorted
const services = {
auth,
database,
logging,
misc,
random,
auth,
session,
};
export { services };

View File

@@ -181,8 +181,19 @@ export class User {
toJSON(): UserData {
return { ...this.data };
}
toString(): string {
return `User(id ${this.id})`;
}
}
// For representing "no user" in contexts where user is optional
export const AnonymousUser = Symbol("AnonymousUser");
export const anonymousUser = User.create("anonymous@example.com", {
id: "-1",
displayName: "Anonymous User",
// FIXME: set createdAt and updatedAt to start of epoch
});
export type MaybeUser = User | typeof AnonymousUser;