mirror of
https://github.com/oxynote/oxynote.git
synced 2026-10-17 19:09:19 +02:00
46 lines
2.2 KiB
TypeScript
46 lines
2.2 KiB
TypeScript
import { ipcMain } from "electron"
|
|
import { authClient } from "./auth-client"
|
|
|
|
// Whitelist of auth operations exposed to the renderer. Each handler runs in
|
|
// main with the electron-store-backed session; the renderer never sees the
|
|
// session cookie, only the operation's result. Adding a new auth op here is
|
|
// the only way to expose it to the renderer.
|
|
//
|
|
// The shared `never` parameter is what lets one record type hold handlers
|
|
// whose better-auth argument types all differ: every one of them accepts
|
|
// `never`, so no signature has to widen to `any`. The IPC payload is asserted
|
|
// to it once, at the boundary below — the auth server validates the shape.
|
|
const handlers: Record<string, (args: never) => Promise<unknown>> = {
|
|
"auth:getSession": () => authClient.getSession(),
|
|
"auth:signInEmailPassword": (args) => authClient.signIn.email(args),
|
|
"auth:signUpEmailPassword": (args) => authClient.signUp.email(args),
|
|
"auth:requestPasswordReset": (args) => authClient.requestPasswordReset(args),
|
|
"auth:changePassword": (args) => authClient.changePassword(args),
|
|
"auth:listAccounts": () => authClient.listAccounts(),
|
|
"auth:updateUser": (args) => authClient.updateUser(args),
|
|
"auth:changeEmail": (args) => authClient.changeEmail(args),
|
|
"auth:deleteUser": (args) => authClient.deleteUser(args),
|
|
"auth:getFullOrganization": () =>
|
|
authClient.organization.getFullOrganization(),
|
|
"auth:checkOrganizationSlug": (args) =>
|
|
authClient.organization.checkSlug(args),
|
|
"auth:createOrganization": (args) => authClient.organization.create(args),
|
|
"auth:setActiveOrganization": (args) =>
|
|
authClient.organization.setActive(args),
|
|
"auth:acceptOrganizationInvitation": (args) =>
|
|
authClient.organization.acceptInvitation(args),
|
|
"auth:updateOrganization": (args) => authClient.organization.update(args),
|
|
"auth:inviteOrganizationMember": (args) =>
|
|
authClient.organization.inviteMember(args),
|
|
"auth:cancelOrganizationInvitation": (args) =>
|
|
authClient.organization.cancelInvitation(args),
|
|
"auth:removeOrganizationMember": (args) =>
|
|
authClient.organization.removeMember(args),
|
|
}
|
|
|
|
export function registerAuthIpcHandlers() {
|
|
for (const [channel, handler] of Object.entries(handlers)) {
|
|
ipcMain.handle(channel, (_event, args: unknown) => handler(args as never))
|
|
}
|
|
}
|