summaryrefslogtreecommitdiffhomepage
path: root/packages/console/function
diff options
context:
space:
mode:
authorFrank <[email protected]>2025-10-16 22:27:28 -0400
committerFrank <[email protected]>2025-10-16 22:28:34 -0400
commit1947580b08b04fc8d81841fa6017f721dec6a3da (patch)
tree5c157189a344ca22d49dac396261182d45251f65 /packages/console/function
parentca9b13e8a2626aca3bb28882cff395c18e0a215c (diff)
downloadopencode-1947580b08b04fc8d81841fa6017f721dec6a3da.tar.gz
opencode-1947580b08b04fc8d81841fa6017f721dec6a3da.zip
wip: zen
Diffstat (limited to 'packages/console/function')
-rw-r--r--packages/console/function/src/auth.ts25
1 files changed, 15 insertions, 10 deletions
diff --git a/packages/console/function/src/auth.ts b/packages/console/function/src/auth.ts
index 590608884..eb31015ed 100644
--- a/packages/console/function/src/auth.ts
+++ b/packages/console/function/src/auth.ts
@@ -12,7 +12,7 @@ import { Workspace } from "@opencode-ai/console-core/workspace.js"
import { Actor } from "@opencode-ai/console-core/actor.js"
import { Resource } from "@opencode-ai/console-resource"
import { User } from "@opencode-ai/console-core/user.js"
-import { and, Database, eq, isNull } from "@opencode-ai/console-core/drizzle/index.js"
+import { and, Database, eq, isNull, or } from "@opencode-ai/console-core/drizzle/index.js"
import { WorkspaceTable } from "@opencode-ai/console-core/schema/workspace.sql.js"
import { UserTable } from "@opencode-ai/console-core/schema/user.sql.js"
import { AuthTable } from "@opencode-ai/console-core/schema/auth.sql.js"
@@ -134,28 +134,33 @@ export default {
if (!subject) throw new Error("No subject found")
if (Resource.App.stage !== "production" && !email.endsWith("@anoma.ly")) {
- throw new Error("Invalid email")
}
// Get account
const accountID = await (async () => {
- // check provider mapping
- const idByProvider = await Database.use(async (tx) =>
+ const matches = await Database.use(async (tx) =>
tx
- .select({ accountID: AuthTable.accountID })
+ .select({
+ provider: AuthTable.provider,
+ accountID: AuthTable.accountID,
+ })
.from(AuthTable)
- .where(and(eq(AuthTable.provider, response.provider), eq(AuthTable.subject, subject)))
- .then((rows) => rows[0]?.accountID),
+ .where(
+ or(
+ and(eq(AuthTable.provider, response.provider), eq(AuthTable.subject, subject)),
+ and(eq(AuthTable.provider, "email"), eq(AuthTable.subject, email)),
+ ),
+ ),
)
- // check email mapping
- const idByEmail = await Account.fromEmail(email).then((x) => x?.id)
+ const idByProvider = matches.find((x) => x.provider === response.provider)?.accountID
+ const idByEmail = matches.find((x) => x.provider === "email")?.accountID
if (idByProvider && idByEmail) return idByProvider
// create account if not found
let accountID = idByProvider ?? idByEmail
if (!accountID) {
console.log("creating account for", email)
- accountID = await Account.create({ email: email! })
+ accountID = await Account.create({})
}
await Database.use(async (tx) =>