mirror of
https://github.com/nestriness/nestri.git
synced 2026-08-02 01:35:18 +03:00
feat: Add user to auth.ts function
This commit is contained in:
@@ -3,7 +3,7 @@ import { RedisClient } from "bun";
|
||||
import { logger } from "hono/logger";
|
||||
import { subjects } from "@/subjects.js";
|
||||
import { issuer } from "@openauthjs/openauth";
|
||||
import { Team } from "@nestri/core/team/index";
|
||||
import { User } from "@nestri/core/user/index";
|
||||
import { RedisStorage } from "./src/storage.js";
|
||||
import { CodeProvider } from "@openauthjs/openauth/provider/code";
|
||||
|
||||
@@ -48,15 +48,17 @@ const app = issuer({
|
||||
let email = res.claims.email;
|
||||
|
||||
if (!email) throw new Error("No email found");
|
||||
let teamID = await Team.fromEmail(email).then((x) => x?.id);
|
||||
if (!teamID) {
|
||||
|
||||
let userID = await User.fromEmail(email).then((x) => x?.id);
|
||||
if (!userID) {
|
||||
console.log("creating account for", email);
|
||||
teamID = await Team.create({
|
||||
userID = await User.create({
|
||||
email: email!,
|
||||
name: null,
|
||||
});
|
||||
}
|
||||
return ctx.subject("team", email!, {
|
||||
teamID: teamID!,
|
||||
return ctx.subject("user", email!, {
|
||||
userID: userID!,
|
||||
email: email,
|
||||
});
|
||||
},
|
||||
|
||||
@@ -2,8 +2,8 @@ import { z } from "zod/v4";
|
||||
import { createSubjects } from "@openauthjs/openauth/subject";
|
||||
|
||||
export const subjects = createSubjects({
|
||||
team: z.object({
|
||||
user: z.object({
|
||||
email: z.email(),
|
||||
teamID: z.string(),
|
||||
userID: z.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user