oneie 2.0.2 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +245 -0
- package/CLAUDE.md +725 -0
- package/LICENSE.md +84 -0
- package/README.md +489 -931
- package/folders.yaml +78 -17
- package/one/.obsidian/app.json +1 -0
- package/one/.obsidian/appearance.json +1 -0
- package/one/.obsidian/core-plugins.json +33 -0
- package/one/.obsidian/workspace.json +211 -0
- package/one/connections/a2a.md +551 -0
- package/one/connections/acp.md +761 -0
- package/one/connections/acps.md +731 -0
- package/one/connections/agentkit.md +349 -0
- package/one/connections/agui.md +767 -0
- package/one/connections/any-backend.md +1702 -0
- package/one/connections/ap2.md +998 -0
- package/one/connections/api-docs.md +1891 -0
- package/one/connections/api.md +2190 -0
- package/one/connections/architecture-diagram.md +94 -0
- package/one/connections/communications.md +449 -0
- package/one/connections/connections.md +339 -0
- package/one/connections/copilotkit.md +1559 -0
- package/one/connections/cryptonetworks.md +781 -0
- package/one/connections/documentation.md +1120 -0
- package/one/connections/effect.md +279 -0
- package/one/connections/elizaos.md +1290 -0
- package/one/connections/inference.md +58 -0
- package/one/connections/kyc.md +632 -0
- package/one/connections/mcp.md +842 -0
- package/one/connections/membership.md +1152 -0
- package/one/connections/middleware.md +1067 -0
- package/one/connections/multitenant.md +1341 -0
- package/one/connections/n8n.md +1015 -0
- package/one/connections/patterns.md +89 -0
- package/one/connections/protocols.md +279 -0
- package/one/connections/relationships.md +107 -0
- package/one/connections/schema.md +587 -0
- package/one/connections/service-layer.md +550 -0
- package/one/connections/structure.md +0 -0
- package/one/connections/vectors.md +207 -0
- package/one/connections/wordpress.md +1302 -0
- package/one/connections/workflow-copy.md +905 -0
- package/one/connections/workflow-examples.md +741 -0
- package/one/connections/workflow.md +905 -0
- package/one/connections/workflows/delegation.md +885 -0
- package/one/connections/workflows/frontend.md +1037 -0
- package/one/connections/workflows/strategy.md +903 -0
- package/one/connections/workflows/tasks.md +698 -0
- package/one/connections/x402.md +1249 -0
- package/one/events/CASCADE-2-BACKEND-AGNOSTIC.md +412 -0
- package/one/events/FEATURE-2-4-COMPLETE.md +302 -0
- package/one/events/FEATURE_2_3_COMPLETE.md +575 -0
- package/one/events/GROUPS-MIGRATION.md +625 -0
- package/one/events/INSTALL-TESTS.md +293 -0
- package/one/events/INTEGRATION-ARCHITECTURE.md +561 -0
- package/one/events/INTEGRATION-CHECKLIST.md +1234 -0
- package/one/events/INTEGRATION-ORCHESTRATION.md +2623 -0
- package/one/events/INTEGRATION-SUMMARY.md +653 -0
- package/one/events/MIGRATION-REPORT.md +435 -0
- package/one/events/MIGRATION.md +69 -0
- package/one/events/README-archived.md +519 -0
- package/one/events/TEST-SUMMARY.md +393 -0
- package/one/events/TESTS-QUICK-REF.md +262 -0
- package/one/events/events.md +545 -0
- package/one/groups/groups.md +543 -0
- package/one/groups/one.md +599 -0
- package/one/groups/revenue.md +673 -0
- package/one/groups/strategy.md +869 -0
- package/one/groups/vision.md +98 -0
- package/one/knowledge/CLOUDFLARE_ENV_SETUP.md +49 -0
- package/one/knowledge/ai-platform.md +305 -0
- package/one/knowledge/architecture-any-backend.md +1366 -0
- package/one/knowledge/architecture-diagram.md +94 -0
- package/one/knowledge/architecture-frontend.md +930 -0
- package/one/knowledge/architecture.md +2077 -0
- package/one/knowledge/crypto.md +960 -0
- package/one/knowledge/docs/flow.md +0 -0
- package/one/knowledge/dsl.md +1660 -0
- package/one/knowledge/files.md +2471 -0
- package/one/knowledge/frontend.md +1038 -0
- package/one/knowledge/hono.md +2109 -0
- package/one/knowledge/implementation-examples.md +2536 -0
- package/one/knowledge/inference-score.md +159 -0
- package/one/knowledge/knowledge.md +642 -0
- package/one/knowledge/language.md +980 -0
- package/one/knowledge/lessons-learned.md +70 -0
- package/one/knowledge/ontology-6-dimensions.md +0 -0
- package/one/knowledge/ontology-documentation.md +356 -0
- package/one/knowledge/ontology-engineering-specification.md +1292 -0
- package/one/knowledge/ontology-engineering.md +1652 -0
- package/one/knowledge/ontology-frontend-copy-2.md +1492 -0
- package/one/knowledge/ontology-frontend-copy.md +753 -0
- package/one/knowledge/ontology-frontend-specifications.md +2188 -0
- package/one/knowledge/ontology-frontend.md +2427 -0
- package/one/knowledge/ontology-minimal.yaml +299 -0
- package/one/knowledge/ontology.md +2830 -0
- package/one/knowledge/ontology.md.backup +2822 -0
- package/one/knowledge/ontology.yaml +1165 -0
- package/one/knowledge/patterns/backend/convex-mutation-pattern.md +100 -0
- package/one/knowledge/patterns/backend/convex-query-pattern.md +88 -0
- package/one/knowledge/patterns/backend/mutation-template.md +231 -0
- package/one/knowledge/patterns/backend/query-template.md +267 -0
- package/one/knowledge/patterns/backend/service-template.md +237 -0
- package/one/knowledge/patterns/design/component-architecture.md +399 -0
- package/one/knowledge/patterns/design/test-driven-design-pattern.md +162 -0
- package/one/knowledge/patterns/design/wireframe-template.md +216 -0
- package/one/knowledge/patterns/frontend/component-template.md +195 -0
- package/one/knowledge/patterns/frontend/form-template.md +276 -0
- package/one/knowledge/patterns/frontend/page-template.md +178 -0
- package/one/knowledge/patterns/frontend/react-component-pattern.md +128 -0
- package/one/knowledge/patterns/test/acceptance-criteria-template.md +378 -0
- package/one/knowledge/patterns/test/technical-test-template.md +544 -0
- package/one/knowledge/patterns/test/test-driven-pattern.md +140 -0
- package/one/knowledge/patterns/test/user-flow-template.md +254 -0
- package/one/knowledge/provider-creation-guide.md +1064 -0
- package/one/knowledge/quality-loop.md +401 -0
- package/one/knowledge/readme.md +131 -0
- package/one/knowledge/rules.md +626 -0
- package/one/knowledge/score.md +67 -0
- package/one/knowledge/specifications.md +855 -0
- package/one/knowledge/tags.md +130 -0
- package/one/knowledge/todo.md +251 -0
- package/one/license.md +84 -0
- package/one/people/anthony-o-connell.md +440 -0
- package/one/people/people.md +567 -0
- package/one/things/CHECKLIST.md +356 -0
- package/one/things/ONE.md +510 -0
- package/one/things/agents/agent-backend.md +1401 -0
- package/one/things/agents/agent-builder.md +955 -0
- package/one/things/agents/agent-clean.md +709 -0
- package/one/things/agents/agent-clone.md +1341 -0
- package/one/things/agents/agent-designer.md +2177 -0
- package/one/things/agents/agent-director.md +1508 -0
- package/one/things/agents/agent-documenter.md +1049 -0
- package/one/things/agents/agent-frontend.md +1119 -0
- package/one/things/agents/agent-integrator.md +1192 -0
- package/one/things/agents/agent-problem-solver.md +1379 -0
- package/one/things/agents/agent-quality.md +1353 -0
- package/one/things/agents/agent-sales.md +986 -0
- package/one/things/cascade/cascade.yaml +464 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts/design.md +470 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts/tests.md +264 -0
- package/one/things/cascade/docs/examples/1-1-agent-prompts.md +486 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/design.md +497 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator/tests.md +227 -0
- package/one/things/cascade/docs/examples/1-2-yaml-orchestrator.md +516 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination/design.md +544 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination/tests.md +223 -0
- package/one/things/cascade/docs/examples/1-3-event-coordination.md +508 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management/design.md +609 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management/tests.md +195 -0
- package/one/things/cascade/docs/examples/1-4-knowledge-management.md +577 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops/design.md +797 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops/tests.md +212 -0
- package/one/things/cascade/docs/examples/1-5-quality-loops.md +641 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure/design.md +610 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure/tests.md +213 -0
- package/one/things/cascade/docs/examples/1-6-numbering-structure.md +575 -0
- package/one/things/cascade/docs/examples/readme.md +222 -0
- package/one/things/cascade/docs/getting-started.md +515 -0
- package/one/things/cascade/docs/workflow.md +1372 -0
- package/one/things/cascade/readme.md +336 -0
- package/one/things/cascade/templates/feature-template.md +267 -0
- package/one/things/claude/agents/advocacy-activation-manager.md +685 -0
- package/one/things/claude/agents/advocacy-campaign-designer.md +663 -0
- package/one/things/claude/agents/analyst.md +483 -0
- package/one/things/claude/agents/architect.md +480 -0
- package/one/things/claude/agents/brand-identity-specialist.md +513 -0
- package/one/things/claude/agents/bstp-token-strategist.md +667 -0
- package/one/things/claude/agents/builder-repo.md +489 -0
- package/one/things/claude/agents/bullstamp-community-builder.md +574 -0
- package/one/things/claude/agents/bullstamp-marketing-orchestrator.md +506 -0
- package/one/things/claude/agents/bulltilt-platform-growth.md +567 -0
- package/one/things/claude/agents/company-bullstamp-character.md +587 -0
- package/one/things/claude/agents/company-bullstamp-community.md +292 -0
- package/one/things/claude/agents/company-bullstamp-marketing.md +292 -0
- package/one/things/claude/agents/company-bullstamp-token.md +292 -0
- package/one/things/claude/agents/company-bulltilt-growth.md +292 -0
- package/one/things/claude/agents/content-bibliography-formatter.md +381 -0
- package/one/things/claude/agents/content-calendar-planner.md +448 -0
- package/one/things/claude/agents/content-chapter-formatter.md +488 -0
- package/one/things/claude/agents/content-formatter.md +546 -0
- package/one/things/claude/agents/content-hook-specialist.md +462 -0
- package/one/things/claude/agents/content-image-formatter.md +535 -0
- package/one/things/claude/agents/content-introduction-formatter.md +485 -0
- package/one/things/claude/agents/content-multiplication-engine.md +556 -0
- package/one/things/claude/agents/content-playbook-writer.md +448 -0
- package/one/things/claude/agents/content-team-manager.md +622 -0
- package/one/things/claude/agents/content-toc-formatter.md +522 -0
- package/one/things/claude/agents/convex-backend-specialist.md +2561 -0
- package/one/things/claude/agents/core-manager.md +582 -0
- package/one/things/claude/agents/core-master.md +403 -0
- package/one/things/claude/agents/cross-functional-manager.md +471 -0
- package/one/things/claude/agents/crypto-airdrop-strategist.md +602 -0
- package/one/things/claude/agents/crypto-analytics-educator.md +553 -0
- package/one/things/claude/agents/crypto-architecture-specialist.md +466 -0
- package/one/things/claude/agents/crypto-community-analyst.md +298 -0
- package/one/things/claude/agents/crypto-community-psychologist.md +509 -0
- package/one/things/claude/agents/crypto-dex-optimization-expert.md +538 -0
- package/one/things/claude/agents/crypto-dex-optimizer.md +292 -0
- package/one/things/claude/agents/crypto-diamond-formation-specialist.md +513 -0
- package/one/things/claude/agents/crypto-diamond-hands.md +292 -0
- package/one/things/claude/agents/crypto-ecosystem-expansion-manager.md +554 -0
- package/one/things/claude/agents/crypto-engagement-specialist.md +540 -0
- package/one/things/claude/agents/crypto-market-researcher.md +292 -0
- package/one/things/claude/agents/crypto-marketing-orchestrator.md +523 -0
- package/one/things/claude/agents/crypto-network-effect-amplifier.md +569 -0
- package/one/things/claude/agents/crypto-optimization-analyst.md +554 -0
- package/one/things/claude/agents/crypto-strategic-synthesizer.md +517 -0
- package/one/things/claude/agents/crypto-team-manager.md +387 -0
- package/one/things/claude/agents/crypto-token-analyst.md +278 -0
- package/one/things/claude/agents/crypto-viral-content-creator.md +546 -0
- package/one/things/claude/agents/crypto-wallet-identification-expert.md +517 -0
- package/one/things/claude/agents/crypto-wallet-identifier.md +292 -0
- package/one/things/claude/agents/customer-journey-designer.md +481 -0
- package/one/things/claude/agents/customer-success-manager.md +581 -0
- package/one/things/claude/agents/dev.md +413 -0
- package/one/things/claude/agents/documenter.md +546 -0
- package/one/things/claude/agents/elevate-marketing-orchestrator.md +410 -0
- package/one/things/claude/agents/engagement-specialist.md +509 -0
- package/one/things/claude/agents/engineering-architect.md +387 -0
- package/one/things/claude/agents/engineering-business-analyst.md +537 -0
- package/one/things/claude/agents/engineering-developer.md +387 -0
- package/one/things/claude/agents/engineering-director.md +282 -0
- package/one/things/claude/agents/engineering-ingestor.md +649 -0
- package/one/things/claude/agents/engineering-product-manager.md +537 -0
- package/one/things/claude/agents/engineering-product-owner.md +537 -0
- package/one/things/claude/agents/engineering-project-coordinator.md +537 -0
- package/one/things/claude/agents/engineering-quality-assurance.md +393 -0
- package/one/things/claude/agents/engineering-team-manager.md +512 -0
- package/one/things/claude/agents/engineering-user-experience.md +387 -0
- package/one/things/claude/agents/framework-elevate-manager.md +294 -0
- package/one/things/claude/agents/improver.md +763 -0
- package/one/things/claude/agents/intelligence-team-manager.md +385 -0
- package/one/things/claude/agents/lead-capture-expert.md +466 -0
- package/one/things/claude/agents/lead-magnet-creator.md +453 -0
- package/one/things/claude/agents/market-research-analyst.md +412 -0
- package/one/things/claude/agents/marketing-brand-identity.md +314 -0
- package/one/things/claude/agents/marketing-content-hooks.md +450 -0
- package/one/things/claude/agents/marketing-content-multiplier.md +326 -0
- package/one/things/claude/agents/marketing-content-poster.md +361 -0
- package/one/things/claude/agents/marketing-customer-journey.md +326 -0
- package/one/things/claude/agents/marketing-director.md +397 -0
- package/one/things/claude/agents/marketing-engagement.md +326 -0
- package/one/things/claude/agents/marketing-lead-capture.md +326 -0
- package/one/things/claude/agents/marketing-lead-magnet.md +326 -0
- package/one/things/claude/agents/marketing-network-effects.md +326 -0
- package/one/things/claude/agents/marketing-nurture-campaigns.md +326 -0
- package/one/things/claude/agents/marketing-share-optimizer.md +326 -0
- package/one/things/claude/agents/marketing-team-manager.md +446 -0
- package/one/things/claude/agents/marketing-viral-growth.md +201 -0
- package/one/things/claude/agents/mission-commander.md +373 -0
- package/one/things/claude/agents/network-effect-analyst.md +587 -0
- package/one/things/claude/agents/nextjs-15-specialist.md +1547 -0
- package/one/things/claude/agents/npx.md +890 -0
- package/one/things/claude/agents/nurture-campaign-manager.md +531 -0
- package/one/things/claude/agents/one-master.md +355 -0
- package/one/things/claude/agents/one-orchestrator.md +315 -0
- package/one/things/claude/agents/one.md +601 -0
- package/one/things/claude/agents/playbook-generator.md +503 -0
- package/one/things/claude/agents/pm.md +326 -0
- package/one/things/claude/agents/po.md +345 -0
- package/one/things/claude/agents/qa.md +336 -0
- package/one/things/claude/agents/research-foundation-analyst.md +307 -0
- package/one/things/claude/agents/research-intelligence-gatherer.md +408 -0
- package/one/things/claude/agents/research-market-analyst.md +307 -0
- package/one/things/claude/agents/research-team-manager.md +482 -0
- package/one/things/claude/agents/sales-environment-optimizer.md +494 -0
- package/one/things/claude/agents/sales-team-manager.md +400 -0
- package/one/things/claude/agents/sales-upsell-strategist.md +307 -0
- package/one/things/claude/agents/service-advocacy-campaigns.md +307 -0
- package/one/things/claude/agents/service-advocacy-manager.md +307 -0
- package/one/things/claude/agents/service-success-manager.md +307 -0
- package/one/things/claude/agents/service-team-manager.md +400 -0
- package/one/things/claude/agents/shadcn-ui-design-system-specialist.md +2302 -0
- package/one/things/claude/agents/share-optimization-specialist.md +551 -0
- package/one/things/claude/agents/sm.md +327 -0
- package/one/things/claude/agents/story-teller.md +473 -0
- package/one/things/claude/agents/task-master.md +596 -0
- package/one/things/claude/agents/tauri-cross-platform-specialist.md +1827 -0
- package/one/things/claude/agents/tester.md +556 -0
- package/one/things/claude/agents/the-bull-character-manager.md +580 -0
- package/one/things/claude/agents/tools-playbook-generator.md +489 -0
- package/one/things/claude/agents/turbo-repo-builder.md +316 -0
- package/one/things/claude/agents/upsell-strategist.md +480 -0
- package/one/things/claude/agents/ux-expert.md +335 -0
- package/one/things/claude/agents/viral-growth-orchestrator.md +497 -0
- package/one/things/claude/claude-code-hooks-development.json +21 -0
- package/one/things/claude/claude-code-hooks-production.json +21 -0
- package/one/things/claude/claude-code-hooks.json +25 -0
- package/one/things/claude/commands/agent.md +104 -0
- package/one/things/claude/commands/cascade-status.md +128 -0
- package/one/things/claude/commands/ingest.md +290 -0
- package/one/things/claude/commands/ingestor.md +136 -0
- package/one/things/claude/commands/mission.md +83 -0
- package/one/things/claude/commands/npx.md +133 -0
- package/one/things/claude/commands/one.md +440 -0
- package/one/things/claude/commands/quality-check.md +204 -0
- package/one/things/claude/commands/smart-route.md +220 -0
- package/one/things/claude/commands/start.md +121 -0
- package/one/things/claude/commands/story.md +83 -0
- package/one/things/claude/commands/task.md +173 -0
- package/one/things/claude/hook-bypass.json +32 -0
- package/one/things/claude/hooks/agent-hook-config.json +427 -0
- package/one/things/claude/hooks/agent-hook-manager.js +525 -0
- package/one/things/claude/hooks/agent-load-balancer.js +271 -0
- package/one/things/claude/hooks/agent-request-interceptor.js +70 -0
- package/one/things/claude/hooks/build-hook.sh +156 -0
- package/one/things/claude/hooks/cascade-feedback.js +297 -0
- package/one/things/claude/hooks/cascade-integration-hooks.js +648 -0
- package/one/things/claude/hooks/cleanup-hook.sh +201 -0
- package/one/things/claude/hooks/continuous-improvement-monitor.js +510 -0
- package/one/things/claude/hooks/file-organization-engine.js +427 -0
- package/one/things/claude/hooks/file-organization-hook.sh +80 -0
- package/one/things/claude/hooks/file-organization-monitor.js +269 -0
- package/one/things/claude/hooks/format-hook.sh +43 -0
- package/one/things/claude/hooks/hook-bypass.sh +293 -0
- package/one/things/claude/hooks/hook-config-manager.js +202 -0
- package/one/things/claude/hooks/hook-debouncer.sh +62 -0
- package/one/things/claude/hooks/hook-logger.sh +89 -0
- package/one/things/claude/hooks/hook-orchestrator.js +662 -0
- package/one/things/claude/hooks/hook-performance-report.js +120 -0
- package/one/things/claude/hooks/lint-hook.sh +140 -0
- package/one/things/claude/hooks/mcp-cascade-integration.js +816 -0
- package/one/things/claude/hooks/memory-optimizer.js +510 -0
- package/one/things/claude/hooks/notification-hook.sh +204 -0
- package/one/things/claude/hooks/ontology-compliance.js +394 -0
- package/one/things/claude/hooks/ontology-hook-manager.js +316 -0
- package/one/things/claude/hooks/ontology-validation-engine.js +317 -0
- package/one/things/claude/hooks/ontology-validation-hook.sh +86 -0
- package/one/things/claude/hooks/performance-metrics.json +25 -0
- package/one/things/claude/hooks/performance-monitoring-hook.js +422 -0
- package/one/things/claude/hooks/quality-scoring-engine.js +834 -0
- package/one/things/claude/hooks/security-hook.sh +256 -0
- package/one/things/claude/hooks/simple-load-balancer.js +238 -0
- package/one/things/claude/hooks/startup-optimizer.js +625 -0
- package/one/things/claude/hooks/story-scoring-system.js +445 -0
- package/one/things/claude/hooks/story-validation-engine.js +473 -0
- package/one/things/claude/hooks/story-validation-hook-enhanced.sh +210 -0
- package/one/things/claude/hooks/story-validation-hook.sh +145 -0
- package/one/things/claude/hooks/structure-synchronizer.js +194 -0
- package/one/things/claude/hooks/sub-agent-output-validator.js +647 -0
- package/one/things/claude/hooks/sub-agent-validation-hook.js +343 -0
- package/one/things/claude/hooks/test-hook.sh +145 -0
- package/one/things/claude/hooks/test-story-validation.sh +170 -0
- package/one/things/claude/hooks/trinity-validation-system.js +392 -0
- package/one/things/claude/settings-local.json +86 -0
- package/one/things/cli/cli-code.md +652 -0
- package/one/things/cli/cli-compiler-code.md +652 -0
- package/one/things/cli/cli.md +1068 -0
- package/one/things/components/card-shadcn.md +929 -0
- package/one/things/components/card.md +1050 -0
- package/one/things/components.md +1669 -0
- package/one/things/componets.md +4 -0
- package/one/things/creator-diagram.md +166 -0
- package/one/things/examples/children/lemonade-stand.md +366 -0
- package/one/things/examples/enterprise/crm-saas.md +1429 -0
- package/one/things/features/1-1-agent-prompts/design.md +470 -0
- package/one/things/features/1-1-agent-prompts/tests.md +264 -0
- package/one/things/features/1-1-agent-prompts.md +486 -0
- package/one/things/features/1-2-yaml-orchestrator/design.md +497 -0
- package/one/things/features/1-2-yaml-orchestrator/tests.md +227 -0
- package/one/things/features/1-2-yaml-orchestrator.md +516 -0
- package/one/things/features/1-3-event-coordination/design.md +544 -0
- package/one/things/features/1-3-event-coordination/tests.md +223 -0
- package/one/things/features/1-3-event-coordination.md +508 -0
- package/one/things/features/1-4-knowledge-management/design.md +609 -0
- package/one/things/features/1-4-knowledge-management/tests.md +195 -0
- package/one/things/features/1-4-knowledge-management.md +577 -0
- package/one/things/features/1-5-quality-loops/design.md +797 -0
- package/one/things/features/1-5-quality-loops/tests.md +212 -0
- package/one/things/features/1-5-quality-loops.md +641 -0
- package/one/things/features/1-6-numbering-structure/design.md +610 -0
- package/one/things/features/1-6-numbering-structure/tests.md +213 -0
- package/one/things/features/1-6-numbering-structure.md +575 -0
- package/one/things/features/2-1-dataprovider-interface.md +2358 -0
- package/one/things/features/2-2-config-system.md +3075 -0
- package/one/things/features/2-3-effectts-services.md +1498 -0
- package/one/things/features/2-4-react-hooks.md +2120 -0
- package/one/things/features/2-5-auth-migration.md +2046 -0
- package/one/things/features/2-6-dashboard-migration.md +1985 -0
- package/one/things/features/2-7-alternative-providers.md +2505 -0
- package/one/things/features/2-7-implementation-report.md +680 -0
- package/one/things/features/2-cli.md +1235 -0
- package/one/things/features/2-design.md +1738 -0
- package/one/things/features/2-tests.md +520 -0
- package/one/things/features/AUTH_HOOKS_IMPLEMENTATION.md +521 -0
- package/one/things/features/DECOUPLING.md +272 -0
- package/one/things/features/DEPLOYMENT.md +452 -0
- package/one/things/features/IMPLEMENTATION_SUMMARY.md +316 -0
- package/one/things/features/dataprovider-interface/1-tests.md +1522 -0
- package/one/things/features/improve.md +843 -0
- package/one/things/features/remove-convex-deps.md +45 -0
- package/one/things/features/top-features.md +79 -0
- package/one/things/features/use-one-backend.md +1180 -0
- package/one/things/ideas/1-create-workflow.md +189 -0
- package/one/things/ideas/2-backend-agnostic-frontend.md +384 -0
- package/one/things/plans/1-create-workflow-status.md +555 -0
- package/one/things/plans/1-create-workflow.md +713 -0
- package/one/things/plans/2-backend-agnostic-frontend.md +543 -0
- package/one/things/plans/3-groups.md +502 -0
- package/one/things/plans/app.md +761 -0
- package/one/things/plans/backend-agnostic-frontend.md +323 -0
- package/one/things/plans/better-auth-any-backend-revised.md +1065 -0
- package/one/things/plans/better-auth-any-backend.md +1852 -0
- package/one/things/plans/better-auth-available-features.md +235 -0
- package/one/things/plans/big-plan.md +38 -0
- package/one/things/plans/convex-better-auth.md +1109 -0
- package/one/things/plans/convex-on-off.md +389 -0
- package/one/things/plans/deploy-to-cloudflare.md +581 -0
- package/one/things/plans/desktop.md +1121 -0
- package/one/things/plans/effect-components.md +1669 -0
- package/one/things/plans/effect.md +973 -0
- package/one/things/plans/email.md +953 -0
- package/one/things/plans/enhance-auth.md +1669 -0
- package/one/things/plans/install-components.md +198 -0
- package/one/things/plans/landing.md +728 -0
- package/one/things/plans/layout.md +205 -0
- package/one/things/plans/mail-backend.md +1308 -0
- package/one/things/plans/mail.md +2624 -0
- package/one/things/plans/next-features.md +83 -0
- package/one/things/plans/one.md +658 -0
- package/one/things/plans/ontology-6-dimensions.md +2216 -0
- package/one/things/plans/ontology-driven-strategy.md +866 -0
- package/one/things/plans/ontology-ui-approach.md +357 -0
- package/one/things/plans/open-agent.md +785 -0
- package/one/things/plans/organizations-to-groups.md +705 -0
- package/one/things/plans/performace.md +90 -0
- package/one/things/plans/release.md +432 -0
- package/one/things/plans/releases.md +809 -0
- package/one/things/plans/repos.md +76 -0
- package/one/things/plans/separate-copy-2.md +1293 -0
- package/one/things/plans/separate-copy-3.md +2458 -0
- package/one/things/plans/separate-copy.md +1293 -0
- package/one/things/plans/separate.md +1983 -0
- package/one/things/plans/shadcn-integration-summary.md +450 -0
- package/one/things/plans/sidebar.md +172 -0
- package/one/things/plans/small-fixes.md +5 -0
- package/one/things/plans/test-backend-connection.md +476 -0
- package/one/things/plans/workflow-files.md +1196 -0
- package/one/things/plans/workflow.md +1372 -0
- package/one/things/products/cascade-landing-page.md +737 -0
- package/one/things/products/cascade.md +1518 -0
- package/one/things/products/context-engineering.md +1427 -0
- package/one/things/products/onthology.md +0 -0
- package/one/things/products/ontology-ui-shadcn.md +1280 -0
- package/one/things/products/ontology-ui.md +1387 -0
- package/one/things/products/ontology.md +717 -0
- package/one/things/products/sdk.md +557 -0
- package/one/things/promptkit.md +903 -0
- package/one/things/service-providers-new.md +982 -0
- package/one/things/service-providers.md +1092 -0
- package/one/things/system.md +600 -0
- package/one/things/tests/2-1-dataprovider-interface.md +1144 -0
- package/one/things/tests/2-1-test-analysis.md +496 -0
- package/one/things/things.md +349 -0
- package/one/things/todo.md +1248 -0
- package/one/things/vision/elegant-interface.md +214 -0
- package/package.json +5 -2
|
@@ -0,0 +1,1852 @@
|
|
|
1
|
+
# Better Auth + ONE Ontology: Universal Authentication
|
|
2
|
+
|
|
3
|
+
**Integrating Better Auth with the ONE 6-dimension ontology using Effect.ts**
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Executive Summary
|
|
8
|
+
|
|
9
|
+
Better Auth is already integrated in our `/frontend` with 6 authentication methods. This plan shows how to make it work with **the ONE 6-dimension ontology** and **ANY backend** (Convex, Supabase, Neon, WordPress) using Effect.ts and the DataProvider pattern.
|
|
10
|
+
|
|
11
|
+
**Key Insight:** Auth maps perfectly to the 6 dimensions: organizations partition auth data, people are the authorized users, sessions are connections, auth actions are events, and all operations use Effect.ts for type-safety.
|
|
12
|
+
|
|
13
|
+
**Architecture:**
|
|
14
|
+
```
|
|
15
|
+
┌─────────────────────────────────────────────────────────┐
|
|
16
|
+
│ Frontend (Astro + React) │
|
|
17
|
+
│ - Better Auth UI (6 auth methods) │
|
|
18
|
+
│ - Effect.ts AuthService (type-safe) │
|
|
19
|
+
│ - useEffectRunner hook │
|
|
20
|
+
│ - Backend-agnostic via DataProvider │
|
|
21
|
+
└────────────────┬────────────────────────────────────────┘
|
|
22
|
+
│ Effect.ts + DataProvider
|
|
23
|
+
↓
|
|
24
|
+
┌─────────────────────────────────────────────────────────┐
|
|
25
|
+
│ AuthService (Effect.ts) │
|
|
26
|
+
│ - signUp → creates person (dimension 2) + event │
|
|
27
|
+
│ - signIn → creates session connection + event │
|
|
28
|
+
│ - signOut → deletes session connection + event │
|
|
29
|
+
│ - All operations org-scoped & backend-agnostic │
|
|
30
|
+
└────────────────┬────────────────────────────────────────┘
|
|
31
|
+
│ DataProvider Interface
|
|
32
|
+
↓
|
|
33
|
+
┌─────────────────────────────────────────────────────────┐
|
|
34
|
+
│ ONE 6-Dimension Ontology │
|
|
35
|
+
│ │
|
|
36
|
+
│ 1. Organizations: Multi-tenant partitioning │
|
|
37
|
+
│ - Each auth operation scoped to organizationId │
|
|
38
|
+
│ - Perfect data isolation │
|
|
39
|
+
│ │
|
|
40
|
+
│ 2. People: Users & authorization │
|
|
41
|
+
│ - type: "creator" thing with role property │
|
|
42
|
+
│ - properties: { email, emailVerified, role } │
|
|
43
|
+
│ - roles: platform_owner, org_owner, org_user │
|
|
44
|
+
│ │
|
|
45
|
+
│ 3. Things: Session devices (optional) │
|
|
46
|
+
│ - type: "device" for session tracking │
|
|
47
|
+
│ │
|
|
48
|
+
│ 4. Connections: Sessions & OAuth links │
|
|
49
|
+
│ - type: "session" → Active user sessions │
|
|
50
|
+
│ - type: "oauth_account" → OAuth providers │
|
|
51
|
+
│ - metadata: { token, expiresAt, provider } │
|
|
52
|
+
│ │
|
|
53
|
+
│ 5. Events: Complete auth audit trail │
|
|
54
|
+
│ - type: "sign_up", "sign_in", "sign_out" │
|
|
55
|
+
│ - actorId: userId (always required) │
|
|
56
|
+
│ - organizationId: which org (always required) │
|
|
57
|
+
│ │
|
|
58
|
+
│ 6. Knowledge: Auth patterns for AI │
|
|
59
|
+
│ - Login behavior patterns │
|
|
60
|
+
│ - Security anomaly detection │
|
|
61
|
+
│ - User preference learning │
|
|
62
|
+
└────────────────┬────────────────────────────────────────┘
|
|
63
|
+
│
|
|
64
|
+
┌───────────┼───────────┬───────────┬───────────┐
|
|
65
|
+
↓ ↓ ↓ ↓ ↓
|
|
66
|
+
┌─────────┐ ┌─────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
|
|
67
|
+
│ Convex │ │Supabase │ │ Neon │ │WordPress │ │ Notion │
|
|
68
|
+
│Provider │ │Provider │ │ Provider │ │ Provider │ │ Provider │
|
|
69
|
+
└─────────┘ └─────────┘ └──────────┘ └──────────┘ └──────────┘
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
**What This Achieves:**
|
|
73
|
+
- ✅ Organizations → multi-tenant auth (perfect isolation)
|
|
74
|
+
- ✅ People → users with roles (authorization built-in)
|
|
75
|
+
- ✅ Things → optional device tracking
|
|
76
|
+
- ✅ Connections → sessions & OAuth (automatic cleanup)
|
|
77
|
+
- ✅ Events → complete audit trail (security & analytics)
|
|
78
|
+
- ✅ Knowledge → AI learns auth patterns
|
|
79
|
+
- ✅ Effect.ts → type-safe, composable operations
|
|
80
|
+
- ✅ Backend-agnostic → swap providers with one line
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Table of Contents
|
|
85
|
+
|
|
86
|
+
1. [ONE Ontology Mapping](#one-ontology-mapping)
|
|
87
|
+
2. [Effect.ts AuthService](#effectts-authservice)
|
|
88
|
+
3. [DataProvider Integration](#dataprovider-integration)
|
|
89
|
+
4. [Backend Implementations](#backend-implementations)
|
|
90
|
+
5. [React Components](#react-components)
|
|
91
|
+
6. [Session Management](#session-management)
|
|
92
|
+
7. [Multi-Tenancy](#multi-tenancy)
|
|
93
|
+
8. [Better Auth Compatibility Layer](#better-auth-compatibility-layer)
|
|
94
|
+
9. [Testing](#testing)
|
|
95
|
+
10. [Migration Strategy](#migration-strategy)
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## ONE 6-Dimension Mapping
|
|
100
|
+
|
|
101
|
+
**Better Auth traditionally uses 4 separate tables. In ONE, we map these to the 6-dimension ontology.**
|
|
102
|
+
|
|
103
|
+
### 1. Organizations → Multi-Tenant Isolation
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
// Dimension 1: Organizations
|
|
107
|
+
// Every auth operation belongs to an organization
|
|
108
|
+
{
|
|
109
|
+
_id: Id<'organizations'>,
|
|
110
|
+
name: string,
|
|
111
|
+
slug: string, // URL-friendly (e.g., "fitnesspro")
|
|
112
|
+
status: 'active' | 'suspended',
|
|
113
|
+
plan: 'starter' | 'pro' | 'enterprise',
|
|
114
|
+
limits: {
|
|
115
|
+
users: number, // Max users in this org
|
|
116
|
+
storage: number,
|
|
117
|
+
apiCalls: number,
|
|
118
|
+
inference: number
|
|
119
|
+
},
|
|
120
|
+
settings: {
|
|
121
|
+
allowSignups: boolean, // Can users self-register?
|
|
122
|
+
requireEmailVerification: boolean,
|
|
123
|
+
enableTwoFactor: boolean,
|
|
124
|
+
allowedDomains?: string[] // Email domain restrictions
|
|
125
|
+
},
|
|
126
|
+
createdAt: number,
|
|
127
|
+
updatedAt: number
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Benefits:**
|
|
132
|
+
- ✅ Perfect multi-tenant isolation → users in Org A can't see Org B
|
|
133
|
+
- ✅ Per-org auth settings → different signup rules per org
|
|
134
|
+
- ✅ Per-org quotas → user limits, rate limits
|
|
135
|
+
- ✅ Per-org billing → track auth costs per organization
|
|
136
|
+
|
|
137
|
+
### 2. People → Separate Table (Dimension 2)
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
// Dimension 2: People (SEPARATE TABLE)
|
|
141
|
+
// Better Auth "user" → ONE "people" table
|
|
142
|
+
{
|
|
143
|
+
_id: Id<'people'>, // NOT Id<'things'>!
|
|
144
|
+
email: string, // Better Auth: email
|
|
145
|
+
username: string, // Unique username
|
|
146
|
+
displayName: string, // Display name
|
|
147
|
+
emailVerified: boolean, // Better Auth: emailVerified
|
|
148
|
+
password?: string, // Hashed (if email/password auth)
|
|
149
|
+
image?: string, // Avatar URL
|
|
150
|
+
|
|
151
|
+
// CRITICAL: Role determines access level
|
|
152
|
+
role: "platform_owner" | "org_owner" | "org_user" | "customer",
|
|
153
|
+
|
|
154
|
+
// Organization context
|
|
155
|
+
organizationId: Id<'organizations'>, // Primary organization
|
|
156
|
+
organizations: Id<'organizations'>[], // All orgs this person belongs to
|
|
157
|
+
permissions?: string[], // Fine-grained permissions
|
|
158
|
+
|
|
159
|
+
// 2FA
|
|
160
|
+
twoFactorEnabled?: boolean,
|
|
161
|
+
twoFactorSecret?: string,
|
|
162
|
+
backupCodes?: string[],
|
|
163
|
+
|
|
164
|
+
// OAuth (stored in connections, but basic info here)
|
|
165
|
+
oauthProviders?: Array<{
|
|
166
|
+
provider: "google" | "github" | "apple",
|
|
167
|
+
providerId: string
|
|
168
|
+
}>,
|
|
169
|
+
|
|
170
|
+
// Profile
|
|
171
|
+
bio?: string,
|
|
172
|
+
location?: string,
|
|
173
|
+
website?: string,
|
|
174
|
+
|
|
175
|
+
createdAt: number,
|
|
176
|
+
updatedAt: number
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
**Why People Are NOT Things:**
|
|
181
|
+
|
|
182
|
+
1. **Different Purpose:**
|
|
183
|
+
- **People** → Authorization & governance (who can do what)
|
|
184
|
+
- **Things** → Domain entities (what exists in the system)
|
|
185
|
+
|
|
186
|
+
2. **Different Relationships:**
|
|
187
|
+
- **People** → Own things, act on things, authorize actions
|
|
188
|
+
- **Things** → Owned by people, acted upon by people
|
|
189
|
+
|
|
190
|
+
3. **Different Lifecycle:**
|
|
191
|
+
- **People** → Permanent identity, cross-org membership
|
|
192
|
+
- **Things** → Created/deleted within org context
|
|
193
|
+
|
|
194
|
+
**Benefits:**
|
|
195
|
+
- ✅ People are first-class dimension → clear authorization model
|
|
196
|
+
- ✅ Role-based access → platform_owner can access all orgs
|
|
197
|
+
- ✅ Multi-org membership → same person, multiple organizations
|
|
198
|
+
- ✅ People act on things → actorId in events always references people
|
|
199
|
+
- ✅ Clean separation → auth logic vs domain logic
|
|
200
|
+
|
|
201
|
+
### 3. Things → Optional Device Tracking
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
// Dimension 3: Things
|
|
205
|
+
// Optional: Track devices/browsers for session management
|
|
206
|
+
{
|
|
207
|
+
_id: Id<'things'>,
|
|
208
|
+
thingType: "device",
|
|
209
|
+
name: string, // E.g., "iPhone 15 Pro - Safari"
|
|
210
|
+
organizationId: Id<'organizations'>,
|
|
211
|
+
status: "active",
|
|
212
|
+
properties: {
|
|
213
|
+
userAgent: string,
|
|
214
|
+
deviceType: "mobile" | "desktop" | "tablet",
|
|
215
|
+
os: string, // "iOS 17.5"
|
|
216
|
+
browser: string, // "Safari 17"
|
|
217
|
+
ipAddress?: string,
|
|
218
|
+
lastSeen: number
|
|
219
|
+
},
|
|
220
|
+
createdAt: number,
|
|
221
|
+
updatedAt: number
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**Benefits:**
|
|
226
|
+
- ✅ Track which devices user is logged in from
|
|
227
|
+
- ✅ Security: Detect suspicious login locations
|
|
228
|
+
- ✅ UX: "Sign out from all devices except this one"
|
|
229
|
+
|
|
230
|
+
### 4. Connections → Sessions & OAuth Links
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
// Dimension 4: Connections
|
|
234
|
+
// Better Auth "session" → ONE connection (type: "session")
|
|
235
|
+
{
|
|
236
|
+
_id: Id<'connections'>,
|
|
237
|
+
fromPersonId: Id<'people'>, // Dimension 2: Person (NOT thing!)
|
|
238
|
+
toThingId: Id<'things'> | null, // Dimension 3: Device (optional)
|
|
239
|
+
relationshipType: "session", // Dimension 4: Connection type
|
|
240
|
+
organizationId: Id<'organizations'>, // Dimension 1: Org scope
|
|
241
|
+
status: "active" | "expired" | "revoked",
|
|
242
|
+
metadata: {
|
|
243
|
+
token: string, // Session token (hashed)
|
|
244
|
+
expiresAt: number, // Unix timestamp
|
|
245
|
+
ipAddress?: string,
|
|
246
|
+
userAgent?: string,
|
|
247
|
+
method: "email" | "google" | "github" | "magic_link",
|
|
248
|
+
lastActivity: number, // Track session activity
|
|
249
|
+
revokedAt?: number,
|
|
250
|
+
revokedReason?: string
|
|
251
|
+
},
|
|
252
|
+
createdAt: number,
|
|
253
|
+
updatedAt: number
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
**Benefits:**
|
|
258
|
+
- ✅ Sessions connect people to devices → clear actor model
|
|
259
|
+
- ✅ Automatic cleanup → delete expired connections
|
|
260
|
+
- ✅ Real-time sync → revoke session = instant logout everywhere
|
|
261
|
+
- ✅ Analytics → count active sessions per person
|
|
262
|
+
- ✅ Security → detect concurrent sessions from different locations
|
|
263
|
+
|
|
264
|
+
**OAuth Account Connection:**
|
|
265
|
+
|
|
266
|
+
```typescript
|
|
267
|
+
// Better Auth "account" → ONE connection (type: "oauth_account")
|
|
268
|
+
{
|
|
269
|
+
_id: Id<'connections'>,
|
|
270
|
+
fromPersonId: Id<'people'>, // Dimension 2: Person (NOT thing!)
|
|
271
|
+
toThingId: Id<'things'>, // OAuth provider thing
|
|
272
|
+
relationshipType: "oauth_account", // Dimension 4
|
|
273
|
+
organizationId: Id<'organizations'>, // Dimension 1
|
|
274
|
+
status: "active" | "revoked",
|
|
275
|
+
metadata: {
|
|
276
|
+
provider: "google" | "github" | "apple",
|
|
277
|
+
providerAccountId: string, // External user ID
|
|
278
|
+
accessToken?: string, // Encrypted
|
|
279
|
+
refreshToken?: string, // Encrypted
|
|
280
|
+
idToken?: string, // JWT from provider
|
|
281
|
+
tokenExpiresAt?: number,
|
|
282
|
+
scope?: string, // OAuth scopes granted
|
|
283
|
+
lastSync: number // Last token refresh
|
|
284
|
+
},
|
|
285
|
+
createdAt: number,
|
|
286
|
+
updatedAt: number
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
**Benefits:**
|
|
291
|
+
- ✅ OAuth accounts connect people to OAuth providers
|
|
292
|
+
- ✅ Multiple providers → person can have Google + GitHub + Apple
|
|
293
|
+
- ✅ Token refresh → update connection metadata
|
|
294
|
+
- ✅ Revocation → disconnect OAuth provider
|
|
295
|
+
|
|
296
|
+
**Note on Schema Design:**
|
|
297
|
+
The connection schema may need to support both:
|
|
298
|
+
- `fromPersonId: Id<'people'>` for people → thing connections
|
|
299
|
+
- `fromThingId: Id<'things'>` for thing → thing connections
|
|
300
|
+
|
|
301
|
+
Or use a union type with discriminator for flexibility.
|
|
302
|
+
|
|
303
|
+
### 5. Events → Complete Auth Audit Trail
|
|
304
|
+
|
|
305
|
+
**Verification Tokens as Events:**
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
// Dimension 5: Events
|
|
309
|
+
// Better Auth "verification" → ONE event (type: "verification_token_created")
|
|
310
|
+
{
|
|
311
|
+
_id: Id<'events'>,
|
|
312
|
+
eventType: "verification_token_created",
|
|
313
|
+
actorId: Id<'people'>, // Dimension 2: Person who requested it
|
|
314
|
+
targetId?: Id<'people'>, // Dimension 2: Person being verified
|
|
315
|
+
organizationId: Id<'organizations'>, // Dimension 1: Org scope
|
|
316
|
+
metadata: {
|
|
317
|
+
identifier: string, // Email or phone
|
|
318
|
+
token: string, // Verification token (hashed)
|
|
319
|
+
verificationType: "email_verification" | "password_reset" | "magic_link",
|
|
320
|
+
expiresAt: number,
|
|
321
|
+
used: boolean, // Consumed?
|
|
322
|
+
usedAt?: number,
|
|
323
|
+
ipAddress?: string,
|
|
324
|
+
userAgent?: string
|
|
325
|
+
},
|
|
326
|
+
timestamp: number,
|
|
327
|
+
createdAt: number
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
**All Auth Actions as Events:**
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
// Log ALL auth actions for complete audit trail
|
|
335
|
+
{
|
|
336
|
+
_id: Id<'events'>,
|
|
337
|
+
eventType: "sign_up" | "sign_in" | "sign_out" | "password_reset" | "email_verified" | "oauth_linked",
|
|
338
|
+
actorId: Id<'people'>, // Dimension 2: Person who did it (REQUIRED)
|
|
339
|
+
targetId?: Id<'things'>, // Dimension 3: Target (session connection, device)
|
|
340
|
+
organizationId: Id<'organizations'>, // Dimension 1: Org scope (REQUIRED)
|
|
341
|
+
metadata: {
|
|
342
|
+
method: "email" | "google" | "github" | "magic_link",
|
|
343
|
+
ipAddress: string,
|
|
344
|
+
userAgent: string,
|
|
345
|
+
success: boolean,
|
|
346
|
+
errorReason?: string, // If failed
|
|
347
|
+
sessionId?: Id<'connections'>, // Reference to session connection
|
|
348
|
+
deviceId?: Id<'things'>, // Reference to device thing
|
|
349
|
+
location?: { // Geo data
|
|
350
|
+
country: string,
|
|
351
|
+
city: string,
|
|
352
|
+
coordinates?: [number, number]
|
|
353
|
+
},
|
|
354
|
+
riskScore?: number // Security risk assessment (0-100)
|
|
355
|
+
},
|
|
356
|
+
timestamp: number,
|
|
357
|
+
createdAt: number
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
**Benefits:**
|
|
362
|
+
- ✅ Complete audit trail → every auth action logged with actorId
|
|
363
|
+
- ✅ Security analytics → detect suspicious patterns (impossible travel, brute force)
|
|
364
|
+
- ✅ User timeline → see complete login history
|
|
365
|
+
- ✅ Compliance → GDPR, SOC2 audit requirements
|
|
366
|
+
- ✅ Debugging → trace auth issues with full context
|
|
367
|
+
- ✅ Real-time monitoring → stream events to security tools
|
|
368
|
+
|
|
369
|
+
### 6. Knowledge → Auth Pattern Intelligence
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
372
|
+
// Dimension 6: Knowledge
|
|
373
|
+
// Embed auth events & user behavior for AI-powered security
|
|
374
|
+
{
|
|
375
|
+
_id: Id<'knowledge'>,
|
|
376
|
+
knowledgeType: "auth_behavior_pattern",
|
|
377
|
+
text: string, // Human-readable description
|
|
378
|
+
embedding: number[], // Vector embedding (768-dim)
|
|
379
|
+
embeddingModel: "text-embedding-3-small",
|
|
380
|
+
sourcePersonId: Id<'people'>, // Dimension 2: Person this pattern belongs to
|
|
381
|
+
organizationId: Id<'organizations'>, // Dimension 1: Org scope
|
|
382
|
+
chunk: {
|
|
383
|
+
personId: Id<'people'>, // Person ID
|
|
384
|
+
eventType: string,
|
|
385
|
+
timestamp: number,
|
|
386
|
+
ipAddress: string,
|
|
387
|
+
location: { country: string, city: string },
|
|
388
|
+
deviceType: string,
|
|
389
|
+
success: boolean
|
|
390
|
+
},
|
|
391
|
+
labels: [
|
|
392
|
+
"auth:login_pattern",
|
|
393
|
+
"security:normal_behavior",
|
|
394
|
+
"time:weekday_morning"
|
|
395
|
+
],
|
|
396
|
+
metadata: {
|
|
397
|
+
behaviorType: "normal" | "suspicious" | "anomalous",
|
|
398
|
+
confidence: number, // 0-1
|
|
399
|
+
riskFactors?: string[], // ["new_device", "new_location"]
|
|
400
|
+
relatedEvents: Id<'events'>[] // Related auth events
|
|
401
|
+
},
|
|
402
|
+
createdAt: number,
|
|
403
|
+
updatedAt: number
|
|
404
|
+
}
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
**Benefits:**
|
|
408
|
+
- ✅ AI learns normal auth patterns per user/org
|
|
409
|
+
- ✅ Detect anomalies: "User always logs in from NYC, now trying from Russia"
|
|
410
|
+
- ✅ Behavioral analysis: "User logs in Mon-Fri 9am-5pm, now 3am Sunday is suspicious"
|
|
411
|
+
- ✅ RAG for security: "Show me similar suspicious login patterns"
|
|
412
|
+
- ✅ Proactive alerts: "Unusual login activity detected"
|
|
413
|
+
|
|
414
|
+
**Example Use Cases:**
|
|
415
|
+
|
|
416
|
+
1. **Security Anomaly Detection:**
|
|
417
|
+
```typescript
|
|
418
|
+
// Query knowledge for similar auth patterns
|
|
419
|
+
const similarPatterns = await queryKnowledge({
|
|
420
|
+
organizationId,
|
|
421
|
+
query: "user login from new location",
|
|
422
|
+
filters: {
|
|
423
|
+
behaviorType: "suspicious",
|
|
424
|
+
labels: ["security:anomaly"]
|
|
425
|
+
},
|
|
426
|
+
k: 5
|
|
427
|
+
})
|
|
428
|
+
|
|
429
|
+
// If similar patterns were flagged before → increase risk score
|
|
430
|
+
if (similarPatterns.length > 3) {
|
|
431
|
+
riskScore += 30
|
|
432
|
+
}
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
2. **Person Preference Learning:**
|
|
436
|
+
```typescript
|
|
437
|
+
// AI learns: "This person prefers Google OAuth, dislikes email/password"
|
|
438
|
+
const personPreferences = await queryKnowledge({
|
|
439
|
+
sourcePersonId: personId,
|
|
440
|
+
labels: ["auth:preference"]
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
// Suggest preferred auth method in UI
|
|
444
|
+
suggestedMethod = personPreferences[0]?.chunk.preferredMethod || "email"
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
3. **Compliance & Audit:**
|
|
448
|
+
```typescript
|
|
449
|
+
// Vector search for all auth events matching audit criteria
|
|
450
|
+
const auditEvents = await queryKnowledge({
|
|
451
|
+
organizationId,
|
|
452
|
+
query: "admin login from outside US",
|
|
453
|
+
labels: ["compliance:geographic_restriction"],
|
|
454
|
+
timeRange: { start: lastQuarter, end: now }
|
|
455
|
+
})
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
---
|
|
459
|
+
|
|
460
|
+
## The Complete 6-Dimension Picture
|
|
461
|
+
|
|
462
|
+
**How all 6 dimensions work together for auth:**
|
|
463
|
+
|
|
464
|
+
```
|
|
465
|
+
1. Organization → "fitnesspro" (Id<'organizations'>)
|
|
466
|
+
└─ Multi-tenant isolation boundary
|
|
467
|
+
└─ Settings: allowSignups=true, requireEmailVerification=true
|
|
468
|
+
|
|
469
|
+
2. Person → "john@fitnesspro.com" (Id<'people'>)
|
|
470
|
+
└─ Separate people table (NOT a thing!)
|
|
471
|
+
└─ role: "org_user"
|
|
472
|
+
└─ organizationId: fitnesspro_id
|
|
473
|
+
|
|
474
|
+
3. Thing → "John's iPhone" (Id<'things'>, type: "device")
|
|
475
|
+
└─ Optional device tracking
|
|
476
|
+
└─ properties: { os: "iOS 17", browser: "Safari" }
|
|
477
|
+
|
|
478
|
+
4. Connection → Session (Id<'connections'>)
|
|
479
|
+
└─ fromPersonId: john_person_id (NOT thingId!)
|
|
480
|
+
└─ toThingId: iphone_thing_id
|
|
481
|
+
└─ type: "session", expiresAt: 7 days
|
|
482
|
+
|
|
483
|
+
5. Event → "sign_in" (Id<'events'>)
|
|
484
|
+
└─ actorId: john_person_id (references people table)
|
|
485
|
+
└─ method: "google", success: true
|
|
486
|
+
└─ organizationId: fitnesspro_id
|
|
487
|
+
|
|
488
|
+
6. Knowledge → Auth pattern (Id<'knowledge'>)
|
|
489
|
+
└─ sourcePersonId: john_person_id
|
|
490
|
+
└─ AI learns: John always logs in from iPhone, weekdays, SF
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
**When John logs in from a new Android device in Moscow:**
|
|
494
|
+
|
|
495
|
+
1. **Organization**: Still "fitnesspro" ✅
|
|
496
|
+
2. **Person**: John (`Id<'people'>`) ✅
|
|
497
|
+
3. **Thing**: New "John's Android" device created (`Id<'things'>`, type: "device")
|
|
498
|
+
4. **Connection**: New session created
|
|
499
|
+
- fromPersonId: john_person_id
|
|
500
|
+
- toThingId: android_device_id
|
|
501
|
+
- type: "session"
|
|
502
|
+
5. **Event**: "sign_in" logged
|
|
503
|
+
- actorId: john_person_id (Person ID!)
|
|
504
|
+
- targetId: android_device_id
|
|
505
|
+
- metadata: { location: "Moscow, Russia" }
|
|
506
|
+
6. **Knowledge**: Vector search finds no similar patterns
|
|
507
|
+
- AI flags as suspicious
|
|
508
|
+
- Risk score: 85/100
|
|
509
|
+
- 2FA required ⚠️
|
|
510
|
+
|
|
511
|
+
**Benefits of 6 Dimensions:**
|
|
512
|
+
- ✅ Perfect multi-tenant isolation (organizations)
|
|
513
|
+
- ✅ Clear authorization model (people with roles, NOT things)
|
|
514
|
+
- ✅ Device tracking (things)
|
|
515
|
+
- ✅ Session management (connections link people → devices)
|
|
516
|
+
- ✅ Complete audit trail (events with people as actors)
|
|
517
|
+
- ✅ AI-powered security (knowledge learns per person)
|
|
518
|
+
|
|
519
|
+
---
|
|
520
|
+
|
|
521
|
+
## Effect.ts AuthService
|
|
522
|
+
|
|
523
|
+
**Wrap all auth operations in Effect.ts for type-safety and composability.**
|
|
524
|
+
|
|
525
|
+
### AuthService Interface
|
|
526
|
+
|
|
527
|
+
```typescript
|
|
528
|
+
// frontend/src/services/AuthService.ts
|
|
529
|
+
import { Effect, Context } from 'effect'
|
|
530
|
+
import { DataProvider, ThingNotFoundError } from '@/providers/DataProvider'
|
|
531
|
+
|
|
532
|
+
// Auth-specific errors
|
|
533
|
+
export class AuthenticationError {
|
|
534
|
+
readonly _tag = 'AuthenticationError'
|
|
535
|
+
constructor(readonly reason: string) {}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
export class InvalidCredentialsError {
|
|
539
|
+
readonly _tag = 'InvalidCredentialsError'
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
export class EmailAlreadyExistsError {
|
|
543
|
+
readonly _tag = 'EmailAlreadyExistsError'
|
|
544
|
+
constructor(readonly email: string) {}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// User type (thing with type: "person")
|
|
548
|
+
export interface User {
|
|
549
|
+
id: string
|
|
550
|
+
email: string
|
|
551
|
+
name: string
|
|
552
|
+
emailVerified: boolean
|
|
553
|
+
image?: string
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// Session type (connection with type: "session")
|
|
557
|
+
export interface Session {
|
|
558
|
+
id: string
|
|
559
|
+
userId: string
|
|
560
|
+
token: string
|
|
561
|
+
expiresAt: number
|
|
562
|
+
method: "email" | "google" | "github"
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// AuthService interface
|
|
566
|
+
export interface AuthServiceInterface {
|
|
567
|
+
// Sign up → creates thing (type: person) + logs event
|
|
568
|
+
signUp: (params: {
|
|
569
|
+
email: string
|
|
570
|
+
password: string
|
|
571
|
+
name: string
|
|
572
|
+
organizationId?: string
|
|
573
|
+
}) => Effect.Effect<User, EmailAlreadyExistsError | Error>
|
|
574
|
+
|
|
575
|
+
// Sign in → creates connection (type: session) + logs event
|
|
576
|
+
signIn: (params: {
|
|
577
|
+
email: string
|
|
578
|
+
password: string
|
|
579
|
+
organizationId?: string
|
|
580
|
+
}) => Effect.Effect<
|
|
581
|
+
{ user: User; session: Session },
|
|
582
|
+
InvalidCredentialsError | Error
|
|
583
|
+
>
|
|
584
|
+
|
|
585
|
+
// OAuth sign in → creates thing + connection (oauth_account) + connection (session)
|
|
586
|
+
signInWithOAuth: (params: {
|
|
587
|
+
provider: "google" | "github" | "apple"
|
|
588
|
+
code: string
|
|
589
|
+
organizationId?: string
|
|
590
|
+
}) => Effect.Effect<
|
|
591
|
+
{ user: User; session: Session },
|
|
592
|
+
AuthenticationError | Error
|
|
593
|
+
>
|
|
594
|
+
|
|
595
|
+
// Sign out → deletes connection (session) + logs event
|
|
596
|
+
signOut: (sessionToken: string) => Effect.Effect<void, Error>
|
|
597
|
+
|
|
598
|
+
// Get current session → queries connection (type: session)
|
|
599
|
+
getSession: (sessionToken: string) => Effect.Effect<
|
|
600
|
+
{ user: User; session: Session } | null,
|
|
601
|
+
Error
|
|
602
|
+
>
|
|
603
|
+
|
|
604
|
+
// Verify email → updates thing properties.emailVerified + logs event
|
|
605
|
+
verifyEmail: (token: string) => Effect.Effect<void, Error>
|
|
606
|
+
|
|
607
|
+
// Reset password → creates event (verification_token) → updates thing password
|
|
608
|
+
requestPasswordReset: (email: string) => Effect.Effect<void, Error>
|
|
609
|
+
resetPassword: (params: {
|
|
610
|
+
token: string
|
|
611
|
+
newPassword: string
|
|
612
|
+
}) => Effect.Effect<void, Error>
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// AuthService implementation (backend-agnostic via DataProvider)
|
|
616
|
+
export class AuthService extends Effect.Service<AuthService>()(
|
|
617
|
+
'AuthService',
|
|
618
|
+
{
|
|
619
|
+
effect: Effect.gen(function* () {
|
|
620
|
+
const provider = yield* DataProvider
|
|
621
|
+
|
|
622
|
+
return {
|
|
623
|
+
// Sign up: create user thing + log event
|
|
624
|
+
signUp: (params) =>
|
|
625
|
+
Effect.gen(function* () {
|
|
626
|
+
// 1. Check if email exists
|
|
627
|
+
const existing = yield* provider.things.list({
|
|
628
|
+
type: 'person',
|
|
629
|
+
organizationId: params.organizationId,
|
|
630
|
+
filters: { 'properties.email': params.email }
|
|
631
|
+
}).pipe(
|
|
632
|
+
Effect.catchAll(() => Effect.succeed([]))
|
|
633
|
+
)
|
|
634
|
+
|
|
635
|
+
if (existing.length > 0) {
|
|
636
|
+
return yield* Effect.fail(
|
|
637
|
+
new EmailAlreadyExistsError(params.email)
|
|
638
|
+
)
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// 2. Hash password (use bcrypt in real app)
|
|
642
|
+
const hashedPassword = yield* hashPassword(params.password)
|
|
643
|
+
|
|
644
|
+
// 3. Create user thing
|
|
645
|
+
const userId = yield* provider.things.create({
|
|
646
|
+
type: 'person',
|
|
647
|
+
name: params.name,
|
|
648
|
+
organizationId: params.organizationId,
|
|
649
|
+
properties: {
|
|
650
|
+
email: params.email,
|
|
651
|
+
emailVerified: false,
|
|
652
|
+
password: hashedPassword
|
|
653
|
+
}
|
|
654
|
+
})
|
|
655
|
+
|
|
656
|
+
// 4. Log sign_up event
|
|
657
|
+
yield* provider.events.log({
|
|
658
|
+
type: 'sign_up',
|
|
659
|
+
actorId: userId,
|
|
660
|
+
organizationId: params.organizationId,
|
|
661
|
+
metadata: {
|
|
662
|
+
method: 'email',
|
|
663
|
+
success: true
|
|
664
|
+
}
|
|
665
|
+
})
|
|
666
|
+
|
|
667
|
+
// 5. Return user
|
|
668
|
+
return {
|
|
669
|
+
id: userId,
|
|
670
|
+
email: params.email,
|
|
671
|
+
name: params.name,
|
|
672
|
+
emailVerified: false
|
|
673
|
+
}
|
|
674
|
+
}),
|
|
675
|
+
|
|
676
|
+
// Sign in: verify credentials + create session connection
|
|
677
|
+
signIn: (params) =>
|
|
678
|
+
Effect.gen(function* () {
|
|
679
|
+
// 1. Find user by email
|
|
680
|
+
const users = yield* provider.things.list({
|
|
681
|
+
type: 'person',
|
|
682
|
+
organizationId: params.organizationId,
|
|
683
|
+
filters: { 'properties.email': params.email }
|
|
684
|
+
})
|
|
685
|
+
|
|
686
|
+
if (users.length === 0) {
|
|
687
|
+
return yield* Effect.fail(new InvalidCredentialsError())
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
const user = users[0]
|
|
691
|
+
|
|
692
|
+
// 2. Verify password
|
|
693
|
+
const valid = yield* verifyPassword(
|
|
694
|
+
params.password,
|
|
695
|
+
user.properties.password
|
|
696
|
+
)
|
|
697
|
+
|
|
698
|
+
if (!valid) {
|
|
699
|
+
// Log failed attempt
|
|
700
|
+
yield* provider.events.log({
|
|
701
|
+
type: 'sign_in',
|
|
702
|
+
actorId: user._id,
|
|
703
|
+
organizationId: params.organizationId,
|
|
704
|
+
metadata: {
|
|
705
|
+
method: 'email',
|
|
706
|
+
success: false,
|
|
707
|
+
errorReason: 'invalid_credentials'
|
|
708
|
+
}
|
|
709
|
+
})
|
|
710
|
+
|
|
711
|
+
return yield* Effect.fail(new InvalidCredentialsError())
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// 3. Generate session token
|
|
715
|
+
const token = yield* generateSecureToken()
|
|
716
|
+
|
|
717
|
+
// 4. Create session connection
|
|
718
|
+
const sessionId = yield* provider.connections.create({
|
|
719
|
+
fromThingId: user._id,
|
|
720
|
+
toThingId: null, // No device tracking yet
|
|
721
|
+
relationshipType: 'session',
|
|
722
|
+
organizationId: params.organizationId,
|
|
723
|
+
metadata: {
|
|
724
|
+
token,
|
|
725
|
+
expiresAt: Date.now() + (7 * 24 * 60 * 60 * 1000), // 7 days
|
|
726
|
+
method: 'email'
|
|
727
|
+
}
|
|
728
|
+
})
|
|
729
|
+
|
|
730
|
+
// 5. Log successful sign_in event
|
|
731
|
+
yield* provider.events.log({
|
|
732
|
+
type: 'sign_in',
|
|
733
|
+
actorId: user._id,
|
|
734
|
+
targetId: sessionId,
|
|
735
|
+
organizationId: params.organizationId,
|
|
736
|
+
metadata: {
|
|
737
|
+
method: 'email',
|
|
738
|
+
success: true
|
|
739
|
+
}
|
|
740
|
+
})
|
|
741
|
+
|
|
742
|
+
return {
|
|
743
|
+
user: {
|
|
744
|
+
id: user._id,
|
|
745
|
+
email: user.properties.email,
|
|
746
|
+
name: user.name,
|
|
747
|
+
emailVerified: user.properties.emailVerified,
|
|
748
|
+
image: user.properties.image
|
|
749
|
+
},
|
|
750
|
+
session: {
|
|
751
|
+
id: sessionId,
|
|
752
|
+
userId: user._id,
|
|
753
|
+
token,
|
|
754
|
+
expiresAt: Date.now() + (7 * 24 * 60 * 60 * 1000),
|
|
755
|
+
method: 'email'
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}),
|
|
759
|
+
|
|
760
|
+
// Sign out: delete session connection + log event
|
|
761
|
+
signOut: (sessionToken) =>
|
|
762
|
+
Effect.gen(function* () {
|
|
763
|
+
// 1. Find session connection by token
|
|
764
|
+
const sessions = yield* provider.connections.list({
|
|
765
|
+
relationshipType: 'session',
|
|
766
|
+
filters: { 'metadata.token': sessionToken }
|
|
767
|
+
})
|
|
768
|
+
|
|
769
|
+
if (sessions.length === 0) {
|
|
770
|
+
return // Session already gone
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
const session = sessions[0]
|
|
774
|
+
|
|
775
|
+
// 2. Delete session connection
|
|
776
|
+
yield* provider.connections.delete(session._id)
|
|
777
|
+
|
|
778
|
+
// 3. Log sign_out event
|
|
779
|
+
yield* provider.events.log({
|
|
780
|
+
type: 'sign_out',
|
|
781
|
+
actorId: session.fromThingId,
|
|
782
|
+
targetId: session._id,
|
|
783
|
+
metadata: {
|
|
784
|
+
method: session.metadata.method,
|
|
785
|
+
success: true
|
|
786
|
+
}
|
|
787
|
+
})
|
|
788
|
+
}),
|
|
789
|
+
|
|
790
|
+
// Get session: query active session connection
|
|
791
|
+
getSession: (sessionToken) =>
|
|
792
|
+
Effect.gen(function* () {
|
|
793
|
+
// 1. Find session connection by token
|
|
794
|
+
const sessions = yield* provider.connections.list({
|
|
795
|
+
relationshipType: 'session',
|
|
796
|
+
filters: { 'metadata.token': sessionToken }
|
|
797
|
+
}).pipe(
|
|
798
|
+
Effect.catchAll(() => Effect.succeed([]))
|
|
799
|
+
)
|
|
800
|
+
|
|
801
|
+
if (sessions.length === 0) {
|
|
802
|
+
return null
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
const session = sessions[0]
|
|
806
|
+
|
|
807
|
+
// 2. Check expiration
|
|
808
|
+
if (session.metadata.expiresAt < Date.now()) {
|
|
809
|
+
// Session expired - delete it
|
|
810
|
+
yield* provider.connections.delete(session._id)
|
|
811
|
+
return null
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// 3. Get user thing
|
|
815
|
+
const user = yield* provider.things.get(session.fromThingId)
|
|
816
|
+
|
|
817
|
+
return {
|
|
818
|
+
user: {
|
|
819
|
+
id: user._id,
|
|
820
|
+
email: user.properties.email,
|
|
821
|
+
name: user.name,
|
|
822
|
+
emailVerified: user.properties.emailVerified,
|
|
823
|
+
image: user.properties.image
|
|
824
|
+
},
|
|
825
|
+
session: {
|
|
826
|
+
id: session._id,
|
|
827
|
+
userId: user._id,
|
|
828
|
+
token: session.metadata.token,
|
|
829
|
+
expiresAt: session.metadata.expiresAt,
|
|
830
|
+
method: session.metadata.method
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}),
|
|
834
|
+
|
|
835
|
+
// Additional methods: verifyEmail, requestPasswordReset, etc.
|
|
836
|
+
// ... (similar pattern using provider.things, provider.events)
|
|
837
|
+
}
|
|
838
|
+
}),
|
|
839
|
+
dependencies: [DataProvider]
|
|
840
|
+
}
|
|
841
|
+
) {}
|
|
842
|
+
|
|
843
|
+
// Helper functions (use crypto libraries in production)
|
|
844
|
+
const hashPassword = (password: string) =>
|
|
845
|
+
Effect.tryPromise({
|
|
846
|
+
try: async () => {
|
|
847
|
+
// Use bcrypt or argon2 in production
|
|
848
|
+
return `hashed_${password}`
|
|
849
|
+
},
|
|
850
|
+
catch: (error) => new Error(String(error))
|
|
851
|
+
})
|
|
852
|
+
|
|
853
|
+
const verifyPassword = (password: string, hash: string) =>
|
|
854
|
+
Effect.tryPromise({
|
|
855
|
+
try: async () => {
|
|
856
|
+
// Use bcrypt.compare or argon2.verify in production
|
|
857
|
+
return hash === `hashed_${password}`
|
|
858
|
+
},
|
|
859
|
+
catch: (error) => new Error(String(error))
|
|
860
|
+
})
|
|
861
|
+
|
|
862
|
+
const generateSecureToken = () =>
|
|
863
|
+
Effect.sync(() => {
|
|
864
|
+
// Use crypto.randomBytes in production
|
|
865
|
+
return Math.random().toString(36).substring(2, 15)
|
|
866
|
+
})
|
|
867
|
+
```
|
|
868
|
+
|
|
869
|
+
**Key Points:**
|
|
870
|
+
- ✅ Uses `DataProvider` → backend-agnostic (works with Convex, Supabase, WordPress)
|
|
871
|
+
- ✅ All operations wrapped in `Effect.gen` → type-safe, composable
|
|
872
|
+
- ✅ Users stored as things (type: person)
|
|
873
|
+
- ✅ Sessions stored as connections (type: session)
|
|
874
|
+
- ✅ All actions logged as events
|
|
875
|
+
- ✅ Multi-tenant by default (organizationId)
|
|
876
|
+
|
|
877
|
+
---
|
|
878
|
+
|
|
879
|
+
## DataProvider Integration
|
|
880
|
+
|
|
881
|
+
**AuthService depends on DataProvider → works with ANY backend**
|
|
882
|
+
|
|
883
|
+
```typescript
|
|
884
|
+
// frontend/src/providers/DataProvider.ts
|
|
885
|
+
export interface DataProvider {
|
|
886
|
+
things: {
|
|
887
|
+
get: (id: string) => Effect.Effect<Thing, ThingNotFoundError>
|
|
888
|
+
list: (params: { type: ThingType; organizationId?: string; filters?: any })
|
|
889
|
+
=> Effect.Effect<Thing[], Error>
|
|
890
|
+
create: (input: { type: ThingType; name: string; properties: any })
|
|
891
|
+
=> Effect.Effect<string, Error>
|
|
892
|
+
update: (id: string, updates: Partial<Thing>) => Effect.Effect<void, Error>
|
|
893
|
+
delete: (id: string) => Effect.Effect<void, Error>
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
connections: {
|
|
897
|
+
create: (input: {
|
|
898
|
+
fromThingId: string
|
|
899
|
+
toThingId: string | null
|
|
900
|
+
relationshipType: ConnectionType
|
|
901
|
+
metadata?: any
|
|
902
|
+
}) => Effect.Effect<string, Error>
|
|
903
|
+
list: (params: { relationshipType: ConnectionType; filters?: any })
|
|
904
|
+
=> Effect.Effect<Connection[], Error>
|
|
905
|
+
delete: (id: string) => Effect.Effect<void, Error>
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
events: {
|
|
909
|
+
log: (event: {
|
|
910
|
+
type: EventType
|
|
911
|
+
actorId: string
|
|
912
|
+
targetId?: string
|
|
913
|
+
metadata?: any
|
|
914
|
+
}) => Effect.Effect<void, Error>
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
```
|
|
918
|
+
|
|
919
|
+
**Backend Providers implement this interface:**
|
|
920
|
+
|
|
921
|
+
### Convex Provider (Example)
|
|
922
|
+
|
|
923
|
+
```typescript
|
|
924
|
+
// frontend/src/providers/convex/ConvexProvider.ts
|
|
925
|
+
import { Effect, Layer } from 'effect'
|
|
926
|
+
import { ConvexHttpClient } from 'convex/browser'
|
|
927
|
+
import { DataProvider } from '../DataProvider'
|
|
928
|
+
import { api } from './api'
|
|
929
|
+
|
|
930
|
+
export class ConvexProvider implements DataProvider {
|
|
931
|
+
constructor(private client: ConvexHttpClient) {}
|
|
932
|
+
|
|
933
|
+
things = {
|
|
934
|
+
create: (input) =>
|
|
935
|
+
Effect.tryPromise({
|
|
936
|
+
try: () => this.client.mutation(api.things.create, input),
|
|
937
|
+
catch: (error) => new Error(String(error))
|
|
938
|
+
}),
|
|
939
|
+
|
|
940
|
+
list: (params) =>
|
|
941
|
+
Effect.tryPromise({
|
|
942
|
+
try: () => this.client.query(api.things.list, params),
|
|
943
|
+
catch: (error) => new Error(String(error))
|
|
944
|
+
}),
|
|
945
|
+
|
|
946
|
+
// ... other methods
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
connections = {
|
|
950
|
+
create: (input) =>
|
|
951
|
+
Effect.tryPromise({
|
|
952
|
+
try: () => this.client.mutation(api.connections.create, input),
|
|
953
|
+
catch: (error) => new Error(String(error))
|
|
954
|
+
}),
|
|
955
|
+
|
|
956
|
+
// ... other methods
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
events = {
|
|
960
|
+
log: (event) =>
|
|
961
|
+
Effect.tryPromise({
|
|
962
|
+
try: () => this.client.mutation(api.events.log, event),
|
|
963
|
+
catch: (error) => new Error(String(error))
|
|
964
|
+
})
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
// Factory function
|
|
969
|
+
export const convexProvider = (config: { url: string }) =>
|
|
970
|
+
Layer.succeed(
|
|
971
|
+
DataProvider,
|
|
972
|
+
new ConvexProvider(new ConvexHttpClient(config.url))
|
|
973
|
+
)
|
|
974
|
+
```
|
|
975
|
+
|
|
976
|
+
**Result:**
|
|
977
|
+
- AuthService calls `provider.things.create()` → works with Convex
|
|
978
|
+
- Change to `supabaseProvider()` → works with Supabase
|
|
979
|
+
- Change to `wordpressProvider()` → works with WordPress
|
|
980
|
+
- **Same AuthService code, different backend**
|
|
981
|
+
|
|
982
|
+
---
|
|
983
|
+
|
|
984
|
+
## React Components
|
|
985
|
+
|
|
986
|
+
**Use AuthService in components via `useEffectRunner` hook**
|
|
987
|
+
|
|
988
|
+
### Sign Up Component
|
|
989
|
+
|
|
990
|
+
```tsx
|
|
991
|
+
// frontend/src/components/auth/SignUpForm.tsx
|
|
992
|
+
import { useEffectRunner } from '@/hooks/useEffectRunner'
|
|
993
|
+
import { AuthService } from '@/services/AuthService'
|
|
994
|
+
import { Effect } from 'effect'
|
|
995
|
+
import { useState } from 'react'
|
|
996
|
+
|
|
997
|
+
export function SignUpForm({ organizationId }: { organizationId: string }) {
|
|
998
|
+
const { run, loading, error } = useEffectRunner()
|
|
999
|
+
const [formData, setFormData] = useState({
|
|
1000
|
+
email: '',
|
|
1001
|
+
password: '',
|
|
1002
|
+
name: ''
|
|
1003
|
+
})
|
|
1004
|
+
|
|
1005
|
+
const handleSubmit = async (e: React.FormEvent) => {
|
|
1006
|
+
e.preventDefault()
|
|
1007
|
+
|
|
1008
|
+
// Define Effect program using AuthService
|
|
1009
|
+
const program = Effect.gen(function* () {
|
|
1010
|
+
const auth = yield* AuthService
|
|
1011
|
+
|
|
1012
|
+
// Sign up → creates thing (type: person) + logs event
|
|
1013
|
+
const user = yield* auth.signUp({
|
|
1014
|
+
...formData,
|
|
1015
|
+
organizationId
|
|
1016
|
+
})
|
|
1017
|
+
|
|
1018
|
+
return user
|
|
1019
|
+
}).pipe(
|
|
1020
|
+
// Handle specific errors
|
|
1021
|
+
Effect.catchTag('EmailAlreadyExistsError', (err) =>
|
|
1022
|
+
Effect.fail(new Error(`Email ${err.email} is already registered`))
|
|
1023
|
+
)
|
|
1024
|
+
)
|
|
1025
|
+
|
|
1026
|
+
// Run Effect program
|
|
1027
|
+
const user = await run(program, {
|
|
1028
|
+
onSuccess: (user) => {
|
|
1029
|
+
// Redirect to verify email page
|
|
1030
|
+
window.location.href = '/verify-email'
|
|
1031
|
+
}
|
|
1032
|
+
})
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
return (
|
|
1036
|
+
<form onSubmit={handleSubmit} className="space-y-4">
|
|
1037
|
+
<input
|
|
1038
|
+
type="text"
|
|
1039
|
+
value={formData.name}
|
|
1040
|
+
onChange={(e) => setFormData({ ...formData, name: e.target.value })}
|
|
1041
|
+
placeholder="Full Name"
|
|
1042
|
+
required
|
|
1043
|
+
/>
|
|
1044
|
+
|
|
1045
|
+
<input
|
|
1046
|
+
type="email"
|
|
1047
|
+
value={formData.email}
|
|
1048
|
+
onChange={(e) => setFormData({ ...formData, email: e.target.value })}
|
|
1049
|
+
placeholder="Email"
|
|
1050
|
+
required
|
|
1051
|
+
/>
|
|
1052
|
+
|
|
1053
|
+
<input
|
|
1054
|
+
type="password"
|
|
1055
|
+
value={formData.password}
|
|
1056
|
+
onChange={(e) => setFormData({ ...formData, password: e.target.value })}
|
|
1057
|
+
placeholder="Password"
|
|
1058
|
+
required
|
|
1059
|
+
/>
|
|
1060
|
+
|
|
1061
|
+
{error && (
|
|
1062
|
+
<div className="text-red-600">{error}</div>
|
|
1063
|
+
)}
|
|
1064
|
+
|
|
1065
|
+
<button type="submit" disabled={loading}>
|
|
1066
|
+
{loading ? 'Creating account...' : 'Sign Up'}
|
|
1067
|
+
</button>
|
|
1068
|
+
</form>
|
|
1069
|
+
)
|
|
1070
|
+
}
|
|
1071
|
+
```
|
|
1072
|
+
|
|
1073
|
+
### Sign In Component
|
|
1074
|
+
|
|
1075
|
+
```tsx
|
|
1076
|
+
// frontend/src/components/auth/SignInForm.tsx
|
|
1077
|
+
import { useEffectRunner } from '@/hooks/useEffectRunner'
|
|
1078
|
+
import { AuthService } from '@/services/AuthService'
|
|
1079
|
+
import { Effect } from 'effect'
|
|
1080
|
+
import { useState } from 'react'
|
|
1081
|
+
|
|
1082
|
+
export function SignInForm({ organizationId }: { organizationId: string }) {
|
|
1083
|
+
const { run, loading, error } = useEffectRunner()
|
|
1084
|
+
const [formData, setFormData] = useState({
|
|
1085
|
+
email: '',
|
|
1086
|
+
password: ''
|
|
1087
|
+
})
|
|
1088
|
+
|
|
1089
|
+
const handleSubmit = async (e: React.FormEvent) => {
|
|
1090
|
+
e.preventDefault()
|
|
1091
|
+
|
|
1092
|
+
// Define Effect program
|
|
1093
|
+
const program = Effect.gen(function* () {
|
|
1094
|
+
const auth = yield* AuthService
|
|
1095
|
+
|
|
1096
|
+
// Sign in → creates connection (type: session) + logs event
|
|
1097
|
+
const result = yield* auth.signIn({
|
|
1098
|
+
...formData,
|
|
1099
|
+
organizationId
|
|
1100
|
+
})
|
|
1101
|
+
|
|
1102
|
+
return result
|
|
1103
|
+
}).pipe(
|
|
1104
|
+
// Handle invalid credentials
|
|
1105
|
+
Effect.catchTag('InvalidCredentialsError', () =>
|
|
1106
|
+
Effect.fail(new Error('Invalid email or password'))
|
|
1107
|
+
)
|
|
1108
|
+
)
|
|
1109
|
+
|
|
1110
|
+
// Run Effect program
|
|
1111
|
+
await run(program, {
|
|
1112
|
+
onSuccess: ({ user, session }) => {
|
|
1113
|
+
// Store session token in cookie/localStorage
|
|
1114
|
+
document.cookie = `session=${session.token}; path=/; max-age=${7 * 24 * 60 * 60}`
|
|
1115
|
+
|
|
1116
|
+
// Redirect to dashboard
|
|
1117
|
+
window.location.href = '/dashboard'
|
|
1118
|
+
}
|
|
1119
|
+
})
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
return (
|
|
1123
|
+
<form onSubmit={handleSubmit} className="space-y-4">
|
|
1124
|
+
<input
|
|
1125
|
+
type="email"
|
|
1126
|
+
value={formData.email}
|
|
1127
|
+
onChange={(e) => setFormData({ ...formData, email: e.target.value })}
|
|
1128
|
+
placeholder="Email"
|
|
1129
|
+
required
|
|
1130
|
+
/>
|
|
1131
|
+
|
|
1132
|
+
<input
|
|
1133
|
+
type="password"
|
|
1134
|
+
value={formData.password}
|
|
1135
|
+
onChange={(e) => setFormData({ ...formData, password: e.target.value })}
|
|
1136
|
+
placeholder="Password"
|
|
1137
|
+
required
|
|
1138
|
+
/>
|
|
1139
|
+
|
|
1140
|
+
{error && (
|
|
1141
|
+
<div className="text-red-600">{error}</div>
|
|
1142
|
+
)}
|
|
1143
|
+
|
|
1144
|
+
<button type="submit" disabled={loading}>
|
|
1145
|
+
{loading ? 'Signing in...' : 'Sign In'}
|
|
1146
|
+
</button>
|
|
1147
|
+
|
|
1148
|
+
<a href="/forgot-password" className="text-sm text-blue-600">
|
|
1149
|
+
Forgot password?
|
|
1150
|
+
</a>
|
|
1151
|
+
</form>
|
|
1152
|
+
)
|
|
1153
|
+
}
|
|
1154
|
+
```
|
|
1155
|
+
|
|
1156
|
+
### OAuth Sign In Button
|
|
1157
|
+
|
|
1158
|
+
```tsx
|
|
1159
|
+
// frontend/src/components/auth/OAuthButton.tsx
|
|
1160
|
+
import { useEffectRunner } from '@/hooks/useEffectRunner'
|
|
1161
|
+
import { AuthService } from '@/services/AuthService'
|
|
1162
|
+
import { Effect } from 'effect'
|
|
1163
|
+
|
|
1164
|
+
interface Props {
|
|
1165
|
+
provider: 'google' | 'github' | 'apple'
|
|
1166
|
+
organizationId: string
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
export function OAuthButton({ provider, organizationId }: Props) {
|
|
1170
|
+
const { run, loading } = useEffectRunner()
|
|
1171
|
+
|
|
1172
|
+
const handleOAuth = async () => {
|
|
1173
|
+
// 1. Redirect to OAuth provider
|
|
1174
|
+
const redirectUrl = `${window.location.origin}/auth/callback/${provider}`
|
|
1175
|
+
const authUrl = getOAuthUrl(provider, redirectUrl)
|
|
1176
|
+
|
|
1177
|
+
window.location.href = authUrl
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
return (
|
|
1181
|
+
<button onClick={handleOAuth} disabled={loading}>
|
|
1182
|
+
{loading ? 'Redirecting...' : `Continue with ${capitalize(provider)}`}
|
|
1183
|
+
</button>
|
|
1184
|
+
)
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
// OAuth callback page
|
|
1188
|
+
// frontend/src/pages/auth/callback/[provider].astro
|
|
1189
|
+
---
|
|
1190
|
+
import { AuthService } from '@/services/AuthService'
|
|
1191
|
+
import { Effect } from 'effect'
|
|
1192
|
+
import { ClientLayer } from '@/services/ClientLayer'
|
|
1193
|
+
|
|
1194
|
+
const { provider } = Astro.params
|
|
1195
|
+
const code = Astro.url.searchParams.get('code')
|
|
1196
|
+
|
|
1197
|
+
if (!code) {
|
|
1198
|
+
return Astro.redirect('/signin?error=no_code')
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
// Sign in with OAuth
|
|
1202
|
+
const program = Effect.gen(function* () {
|
|
1203
|
+
const auth = yield* AuthService
|
|
1204
|
+
|
|
1205
|
+
return yield* auth.signInWithOAuth({
|
|
1206
|
+
provider: provider as 'google' | 'github',
|
|
1207
|
+
code,
|
|
1208
|
+
organizationId: Astro.locals.organizationId
|
|
1209
|
+
})
|
|
1210
|
+
})
|
|
1211
|
+
|
|
1212
|
+
try {
|
|
1213
|
+
const { user, session } = await Effect.runPromise(
|
|
1214
|
+
program.pipe(Effect.provide(ClientLayer))
|
|
1215
|
+
)
|
|
1216
|
+
|
|
1217
|
+
// Set session cookie
|
|
1218
|
+
Astro.cookies.set('session', session.token, {
|
|
1219
|
+
path: '/',
|
|
1220
|
+
maxAge: 7 * 24 * 60 * 60,
|
|
1221
|
+
httpOnly: true,
|
|
1222
|
+
secure: true
|
|
1223
|
+
})
|
|
1224
|
+
|
|
1225
|
+
return Astro.redirect('/dashboard')
|
|
1226
|
+
} catch (error) {
|
|
1227
|
+
return Astro.redirect(`/signin?error=${error.message}`)
|
|
1228
|
+
}
|
|
1229
|
+
---
|
|
1230
|
+
```
|
|
1231
|
+
|
|
1232
|
+
**Key Points:**
|
|
1233
|
+
- ✅ Components use `useEffectRunner` hook
|
|
1234
|
+
- ✅ All auth operations wrapped in `Effect.gen`
|
|
1235
|
+
- ✅ Typed error handling with `catchTag`
|
|
1236
|
+
- ✅ Backend-agnostic → AuthService uses DataProvider
|
|
1237
|
+
- ✅ Sessions stored as connections → automatic real-time sync
|
|
1238
|
+
|
|
1239
|
+
---
|
|
1240
|
+
|
|
1241
|
+
## Backend Implementations
|
|
1242
|
+
|
|
1243
|
+
**Each backend implements the ontology differently, but AuthService stays the same**
|
|
1244
|
+
|
|
1245
|
+
### Convex Backend
|
|
1246
|
+
|
|
1247
|
+
```typescript
|
|
1248
|
+
// backend/convex/schema.ts
|
|
1249
|
+
import { defineSchema, defineTable } from "convex/server"
|
|
1250
|
+
import { v } from "convex/values"
|
|
1251
|
+
|
|
1252
|
+
export default defineSchema({
|
|
1253
|
+
// Users = things with type: "person"
|
|
1254
|
+
things: defineTable({
|
|
1255
|
+
type: v.string(), // "person", "course", "product", etc.
|
|
1256
|
+
name: v.string(),
|
|
1257
|
+
organizationId: v.string(),
|
|
1258
|
+
status: v.string(),
|
|
1259
|
+
properties: v.any(), // { email, emailVerified, password, ... }
|
|
1260
|
+
createdAt: v.number(),
|
|
1261
|
+
updatedAt: v.number()
|
|
1262
|
+
})
|
|
1263
|
+
.index("by_type", ["type"])
|
|
1264
|
+
.index("by_organization", ["organizationId"])
|
|
1265
|
+
.index("by_email", ["properties.email"]), // For fast user lookup
|
|
1266
|
+
|
|
1267
|
+
// Sessions = connections with relationshipType: "session"
|
|
1268
|
+
connections: defineTable({
|
|
1269
|
+
fromThingId: v.string(), // User ID
|
|
1270
|
+
toThingId: v.union(v.string(), v.null()), // Device ID (optional)
|
|
1271
|
+
relationshipType: v.string(), // "session", "oauth_account", etc.
|
|
1272
|
+
organizationId: v.string(),
|
|
1273
|
+
status: v.string(),
|
|
1274
|
+
metadata: v.any(), // { token, expiresAt, method, ... }
|
|
1275
|
+
createdAt: v.number(),
|
|
1276
|
+
updatedAt: v.number()
|
|
1277
|
+
})
|
|
1278
|
+
.index("by_type", ["relationshipType"])
|
|
1279
|
+
.index("by_from", ["fromThingId"])
|
|
1280
|
+
.index("by_token", ["metadata.token"]), // For fast session lookup
|
|
1281
|
+
|
|
1282
|
+
// Auth events = events with type: "sign_up", "sign_in", etc.
|
|
1283
|
+
events: defineTable({
|
|
1284
|
+
type: v.string(), // "sign_up", "sign_in", "sign_out", etc.
|
|
1285
|
+
actorId: v.string(),
|
|
1286
|
+
targetId: v.optional(v.string()),
|
|
1287
|
+
organizationId: v.string(),
|
|
1288
|
+
metadata: v.any(),
|
|
1289
|
+
timestamp: v.number(),
|
|
1290
|
+
createdAt: v.number()
|
|
1291
|
+
})
|
|
1292
|
+
.index("by_type", ["type"])
|
|
1293
|
+
.index("by_actor", ["actorId"])
|
|
1294
|
+
.index("by_timestamp", ["timestamp"])
|
|
1295
|
+
})
|
|
1296
|
+
```
|
|
1297
|
+
|
|
1298
|
+
**Result:** Users, sessions, OAuth accounts all stored in the ontology!
|
|
1299
|
+
|
|
1300
|
+
### Supabase Backend
|
|
1301
|
+
|
|
1302
|
+
```sql
|
|
1303
|
+
-- Users = things with type: "person"
|
|
1304
|
+
CREATE TABLE things (
|
|
1305
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
1306
|
+
type TEXT NOT NULL,
|
|
1307
|
+
name TEXT NOT NULL,
|
|
1308
|
+
"organizationId" TEXT NOT NULL,
|
|
1309
|
+
status TEXT NOT NULL,
|
|
1310
|
+
properties JSONB NOT NULL, -- { email, emailVerified, password, ... }
|
|
1311
|
+
"createdAt" BIGINT NOT NULL,
|
|
1312
|
+
"updatedAt" BIGINT NOT NULL
|
|
1313
|
+
);
|
|
1314
|
+
|
|
1315
|
+
CREATE INDEX idx_things_type ON things(type);
|
|
1316
|
+
CREATE INDEX idx_things_email ON things((properties->>'email'));
|
|
1317
|
+
|
|
1318
|
+
-- Sessions = connections with relationshipType: "session"
|
|
1319
|
+
CREATE TABLE connections (
|
|
1320
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
1321
|
+
"fromThingId" TEXT NOT NULL,
|
|
1322
|
+
"toThingId" TEXT,
|
|
1323
|
+
"relationshipType" TEXT NOT NULL,
|
|
1324
|
+
"organizationId" TEXT NOT NULL,
|
|
1325
|
+
status TEXT NOT NULL,
|
|
1326
|
+
metadata JSONB NOT NULL, -- { token, expiresAt, method, ... }
|
|
1327
|
+
"createdAt" BIGINT NOT NULL,
|
|
1328
|
+
"updatedAt" BIGINT NOT NULL
|
|
1329
|
+
);
|
|
1330
|
+
|
|
1331
|
+
CREATE INDEX idx_connections_type ON connections("relationshipType");
|
|
1332
|
+
CREATE INDEX idx_connections_token ON connections((metadata->>'token'));
|
|
1333
|
+
|
|
1334
|
+
-- Auth events = events
|
|
1335
|
+
CREATE TABLE events (
|
|
1336
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
1337
|
+
type TEXT NOT NULL,
|
|
1338
|
+
"actorId" TEXT NOT NULL,
|
|
1339
|
+
"targetId" TEXT,
|
|
1340
|
+
"organizationId" TEXT NOT NULL,
|
|
1341
|
+
metadata JSONB NOT NULL,
|
|
1342
|
+
timestamp BIGINT NOT NULL,
|
|
1343
|
+
"createdAt" BIGINT NOT NULL
|
|
1344
|
+
);
|
|
1345
|
+
|
|
1346
|
+
CREATE INDEX idx_events_type ON events(type);
|
|
1347
|
+
CREATE INDEX idx_events_actor ON events("actorId");
|
|
1348
|
+
```
|
|
1349
|
+
|
|
1350
|
+
**Result:** Same ontology, different database (PostgreSQL instead of Convex)
|
|
1351
|
+
|
|
1352
|
+
---
|
|
1353
|
+
|
|
1354
|
+
## Session Management
|
|
1355
|
+
|
|
1356
|
+
**Sessions are connections → automatic lifecycle management**
|
|
1357
|
+
|
|
1358
|
+
### Session Middleware
|
|
1359
|
+
|
|
1360
|
+
```typescript
|
|
1361
|
+
// frontend/src/middleware.ts
|
|
1362
|
+
import { defineMiddleware } from 'astro:middleware'
|
|
1363
|
+
import { AuthService } from '@/services/AuthService'
|
|
1364
|
+
import { Effect } from 'effect'
|
|
1365
|
+
import { ClientLayer } from '@/services/ClientLayer'
|
|
1366
|
+
|
|
1367
|
+
export const onRequest = defineMiddleware(async (context, next) => {
|
|
1368
|
+
// Get session token from cookie
|
|
1369
|
+
const sessionToken = context.cookies.get('session')?.value
|
|
1370
|
+
|
|
1371
|
+
if (!sessionToken) {
|
|
1372
|
+
context.locals.user = null
|
|
1373
|
+
context.locals.session = null
|
|
1374
|
+
return next()
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
// Verify session using AuthService
|
|
1378
|
+
const program = Effect.gen(function* () {
|
|
1379
|
+
const auth = yield* AuthService
|
|
1380
|
+
return yield* auth.getSession(sessionToken)
|
|
1381
|
+
})
|
|
1382
|
+
|
|
1383
|
+
try {
|
|
1384
|
+
const result = await Effect.runPromise(
|
|
1385
|
+
program.pipe(Effect.provide(ClientLayer))
|
|
1386
|
+
)
|
|
1387
|
+
|
|
1388
|
+
if (result) {
|
|
1389
|
+
context.locals.user = result.user
|
|
1390
|
+
context.locals.session = result.session
|
|
1391
|
+
}
|
|
1392
|
+
} catch (error) {
|
|
1393
|
+
// Session invalid - clear cookie
|
|
1394
|
+
context.cookies.delete('session')
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
return next()
|
|
1398
|
+
})
|
|
1399
|
+
```
|
|
1400
|
+
|
|
1401
|
+
### Protected Routes
|
|
1402
|
+
|
|
1403
|
+
```astro
|
|
1404
|
+
---
|
|
1405
|
+
// frontend/src/pages/dashboard.astro
|
|
1406
|
+
const user = Astro.locals.user
|
|
1407
|
+
|
|
1408
|
+
if (!user) {
|
|
1409
|
+
return Astro.redirect('/signin')
|
|
1410
|
+
}
|
|
1411
|
+
---
|
|
1412
|
+
|
|
1413
|
+
<Layout title="Dashboard">
|
|
1414
|
+
<h1>Welcome, {user.name}!</h1>
|
|
1415
|
+
<p>Email: {user.email}</p>
|
|
1416
|
+
</Layout>
|
|
1417
|
+
```
|
|
1418
|
+
|
|
1419
|
+
**Session Benefits:**
|
|
1420
|
+
- ✅ Stored as connections → query active sessions
|
|
1421
|
+
- ✅ Automatic expiration → status="expired" when expiresAt passed
|
|
1422
|
+
- ✅ Real-time revocation → delete connection = logged out everywhere
|
|
1423
|
+
- ✅ Analytics → count sessions per user, track login patterns
|
|
1424
|
+
|
|
1425
|
+
---
|
|
1426
|
+
|
|
1427
|
+
## Multi-Tenancy
|
|
1428
|
+
|
|
1429
|
+
**Users and sessions are automatically scoped to organizations**
|
|
1430
|
+
|
|
1431
|
+
### Organization-Based Sign Up
|
|
1432
|
+
|
|
1433
|
+
```typescript
|
|
1434
|
+
// frontend/src/pages/[orgSlug]/signup.astro
|
|
1435
|
+
---
|
|
1436
|
+
import { SignUpForm } from '@/components/auth/SignUpForm'
|
|
1437
|
+
|
|
1438
|
+
// Get org from subdomain via middleware
|
|
1439
|
+
const org = Astro.locals.organization
|
|
1440
|
+
|
|
1441
|
+
if (!org) {
|
|
1442
|
+
return Astro.redirect('/404')
|
|
1443
|
+
}
|
|
1444
|
+
---
|
|
1445
|
+
|
|
1446
|
+
<Layout title={`Sign up for ${org.name}`}>
|
|
1447
|
+
<h1>Create your {org.name} account</h1>
|
|
1448
|
+
|
|
1449
|
+
<!-- SignUpForm automatically uses org.id -->
|
|
1450
|
+
<SignUpForm client:load organizationId={org._id} />
|
|
1451
|
+
</Layout>
|
|
1452
|
+
```
|
|
1453
|
+
|
|
1454
|
+
**How It Works:**
|
|
1455
|
+
1. User visits `fitnesspro.one.ie/signup`
|
|
1456
|
+
2. Middleware extracts `fitnesspro` → queries organization thing
|
|
1457
|
+
3. Sign up form passes `organizationId` to AuthService
|
|
1458
|
+
4. User thing created with `organizationId: fitnesspro_id`
|
|
1459
|
+
5. Session connection created with `organizationId: fitnesspro_id`
|
|
1460
|
+
6. All queries automatically filtered by `organizationId`
|
|
1461
|
+
|
|
1462
|
+
**Benefits:**
|
|
1463
|
+
- ✅ Data isolation → users can't access other orgs
|
|
1464
|
+
- ✅ Automatic scoping → all auth operations org-scoped
|
|
1465
|
+
- ✅ Multi-org users → same email, different orgs
|
|
1466
|
+
- ✅ Session tracking → see which org user is logged into
|
|
1467
|
+
|
|
1468
|
+
---
|
|
1469
|
+
|
|
1470
|
+
## Better Auth Compatibility Layer
|
|
1471
|
+
|
|
1472
|
+
**Optional: Wrap ONE's AuthService to match Better Auth API**
|
|
1473
|
+
|
|
1474
|
+
If you have existing Better Auth code and want to migrate gradually:
|
|
1475
|
+
|
|
1476
|
+
```typescript
|
|
1477
|
+
// frontend/src/auth/better-auth-compat.ts
|
|
1478
|
+
import { AuthService } from '@/services/AuthService'
|
|
1479
|
+
import { Effect } from 'effect'
|
|
1480
|
+
import { ClientLayer } from '@/services/ClientLayer'
|
|
1481
|
+
|
|
1482
|
+
// Better Auth API compatibility layer
|
|
1483
|
+
export const betterAuth = {
|
|
1484
|
+
api: {
|
|
1485
|
+
signUp: {
|
|
1486
|
+
email: async (params: { email: string; password: string; name: string }) => {
|
|
1487
|
+
const program = Effect.gen(function* () {
|
|
1488
|
+
const auth = yield* AuthService
|
|
1489
|
+
return yield* auth.signUp({
|
|
1490
|
+
...params,
|
|
1491
|
+
organizationId: getCurrentOrgId()
|
|
1492
|
+
})
|
|
1493
|
+
})
|
|
1494
|
+
|
|
1495
|
+
return Effect.runPromise(program.pipe(Effect.provide(ClientLayer)))
|
|
1496
|
+
}
|
|
1497
|
+
},
|
|
1498
|
+
|
|
1499
|
+
signIn: {
|
|
1500
|
+
email: async (params: { email: string; password: string }) => {
|
|
1501
|
+
const program = Effect.gen(function* () {
|
|
1502
|
+
const auth = yield* AuthService
|
|
1503
|
+
return yield* auth.signIn({
|
|
1504
|
+
...params,
|
|
1505
|
+
organizationId: getCurrentOrgId()
|
|
1506
|
+
})
|
|
1507
|
+
})
|
|
1508
|
+
|
|
1509
|
+
return Effect.runPromise(program.pipe(Effect.provide(ClientLayer)))
|
|
1510
|
+
}
|
|
1511
|
+
},
|
|
1512
|
+
|
|
1513
|
+
signOut: async () => {
|
|
1514
|
+
const sessionToken = getSessionToken()
|
|
1515
|
+
if (!sessionToken) return
|
|
1516
|
+
|
|
1517
|
+
const program = Effect.gen(function* () {
|
|
1518
|
+
const auth = yield* AuthService
|
|
1519
|
+
return yield* auth.signOut(sessionToken)
|
|
1520
|
+
})
|
|
1521
|
+
|
|
1522
|
+
return Effect.runPromise(program.pipe(Effect.provide(ClientLayer)))
|
|
1523
|
+
},
|
|
1524
|
+
|
|
1525
|
+
getSession: async () => {
|
|
1526
|
+
const sessionToken = getSessionToken()
|
|
1527
|
+
if (!sessionToken) return null
|
|
1528
|
+
|
|
1529
|
+
const program = Effect.gen(function* () {
|
|
1530
|
+
const auth = yield* AuthService
|
|
1531
|
+
return yield* auth.getSession(sessionToken)
|
|
1532
|
+
})
|
|
1533
|
+
|
|
1534
|
+
return Effect.runPromise(program.pipe(Effect.provide(ClientLayer)))
|
|
1535
|
+
}
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
// Helper functions
|
|
1540
|
+
function getCurrentOrgId(): string {
|
|
1541
|
+
// Extract from subdomain or context
|
|
1542
|
+
return globalThis.currentOrgId || ''
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
function getSessionToken(): string | null {
|
|
1546
|
+
// Read from cookie
|
|
1547
|
+
const match = document.cookie.match(/session=([^;]+)/)
|
|
1548
|
+
return match ? match[1] : null
|
|
1549
|
+
}
|
|
1550
|
+
```
|
|
1551
|
+
|
|
1552
|
+
**Result:** Existing Better Auth UI components work with ONE ontology!
|
|
1553
|
+
|
|
1554
|
+
---
|
|
1555
|
+
|
|
1556
|
+
## Testing
|
|
1557
|
+
|
|
1558
|
+
**Effect.ts test layers make testing easy**
|
|
1559
|
+
|
|
1560
|
+
```typescript
|
|
1561
|
+
// frontend/src/services/__tests__/AuthService.test.ts
|
|
1562
|
+
import { describe, it, expect } from 'vitest'
|
|
1563
|
+
import { Effect, Layer } from 'effect'
|
|
1564
|
+
import { AuthService } from '../AuthService'
|
|
1565
|
+
import { DataProvider } from '@/providers/DataProvider'
|
|
1566
|
+
|
|
1567
|
+
// Mock DataProvider
|
|
1568
|
+
const mockThings: any[] = []
|
|
1569
|
+
const mockConnections: any[] = []
|
|
1570
|
+
const mockEvents: any[] = []
|
|
1571
|
+
|
|
1572
|
+
const MockDataProvider = Layer.succeed(DataProvider, {
|
|
1573
|
+
things: {
|
|
1574
|
+
list: (params) =>
|
|
1575
|
+
Effect.succeed(
|
|
1576
|
+
mockThings.filter(t => t.type === params.type)
|
|
1577
|
+
),
|
|
1578
|
+
|
|
1579
|
+
create: (input) =>
|
|
1580
|
+
Effect.sync(() => {
|
|
1581
|
+
const id = `thing_${Date.now()}`
|
|
1582
|
+
mockThings.push({ _id: id, ...input })
|
|
1583
|
+
return id
|
|
1584
|
+
}),
|
|
1585
|
+
|
|
1586
|
+
get: (id) =>
|
|
1587
|
+
Effect.succeed(mockThings.find(t => t._id === id)!)
|
|
1588
|
+
},
|
|
1589
|
+
|
|
1590
|
+
connections: {
|
|
1591
|
+
create: (input) =>
|
|
1592
|
+
Effect.sync(() => {
|
|
1593
|
+
const id = `conn_${Date.now()}`
|
|
1594
|
+
mockConnections.push({ _id: id, ...input })
|
|
1595
|
+
return id
|
|
1596
|
+
}),
|
|
1597
|
+
|
|
1598
|
+
list: (params) =>
|
|
1599
|
+
Effect.succeed(
|
|
1600
|
+
mockConnections.filter(c =>
|
|
1601
|
+
c.relationshipType === params.relationshipType
|
|
1602
|
+
)
|
|
1603
|
+
),
|
|
1604
|
+
|
|
1605
|
+
delete: (id) =>
|
|
1606
|
+
Effect.sync(() => {
|
|
1607
|
+
const index = mockConnections.findIndex(c => c._id === id)
|
|
1608
|
+
mockConnections.splice(index, 1)
|
|
1609
|
+
})
|
|
1610
|
+
},
|
|
1611
|
+
|
|
1612
|
+
events: {
|
|
1613
|
+
log: (event) =>
|
|
1614
|
+
Effect.sync(() => {
|
|
1615
|
+
mockEvents.push(event)
|
|
1616
|
+
})
|
|
1617
|
+
}
|
|
1618
|
+
})
|
|
1619
|
+
|
|
1620
|
+
describe('AuthService', () => {
|
|
1621
|
+
it('signs up a new user', async () => {
|
|
1622
|
+
const program = Effect.gen(function* () {
|
|
1623
|
+
const auth = yield* AuthService
|
|
1624
|
+
|
|
1625
|
+
const user = yield* auth.signUp({
|
|
1626
|
+
email: 'test@example.com',
|
|
1627
|
+
password: 'password123',
|
|
1628
|
+
name: 'Test User',
|
|
1629
|
+
organizationId: 'org_123'
|
|
1630
|
+
})
|
|
1631
|
+
|
|
1632
|
+
return user
|
|
1633
|
+
})
|
|
1634
|
+
|
|
1635
|
+
const user = await Effect.runPromise(
|
|
1636
|
+
program.pipe(
|
|
1637
|
+
Effect.provide(AuthService.Default),
|
|
1638
|
+
Effect.provide(MockDataProvider)
|
|
1639
|
+
)
|
|
1640
|
+
)
|
|
1641
|
+
|
|
1642
|
+
expect(user.email).toBe('test@example.com')
|
|
1643
|
+
expect(user.name).toBe('Test User')
|
|
1644
|
+
expect(mockThings.length).toBe(1)
|
|
1645
|
+
expect(mockEvents.length).toBe(1) // sign_up event logged
|
|
1646
|
+
})
|
|
1647
|
+
|
|
1648
|
+
it('signs in existing user', async () => {
|
|
1649
|
+
// Pre-populate mock user
|
|
1650
|
+
mockThings.push({
|
|
1651
|
+
_id: 'user_1',
|
|
1652
|
+
type: 'person',
|
|
1653
|
+
name: 'Test User',
|
|
1654
|
+
properties: {
|
|
1655
|
+
email: 'test@example.com',
|
|
1656
|
+
password: 'hashed_password123',
|
|
1657
|
+
emailVerified: true
|
|
1658
|
+
}
|
|
1659
|
+
})
|
|
1660
|
+
|
|
1661
|
+
const program = Effect.gen(function* () {
|
|
1662
|
+
const auth = yield* AuthService
|
|
1663
|
+
|
|
1664
|
+
const result = yield* auth.signIn({
|
|
1665
|
+
email: 'test@example.com',
|
|
1666
|
+
password: 'password123',
|
|
1667
|
+
organizationId: 'org_123'
|
|
1668
|
+
})
|
|
1669
|
+
|
|
1670
|
+
return result
|
|
1671
|
+
})
|
|
1672
|
+
|
|
1673
|
+
const result = await Effect.runPromise(
|
|
1674
|
+
program.pipe(
|
|
1675
|
+
Effect.provide(AuthService.Default),
|
|
1676
|
+
Effect.provide(MockDataProvider)
|
|
1677
|
+
)
|
|
1678
|
+
)
|
|
1679
|
+
|
|
1680
|
+
expect(result.user.email).toBe('test@example.com')
|
|
1681
|
+
expect(result.session.userId).toBe('user_1')
|
|
1682
|
+
expect(mockConnections.length).toBe(1) // session connection created
|
|
1683
|
+
expect(mockEvents.length).toBe(1) // sign_in event logged
|
|
1684
|
+
})
|
|
1685
|
+
})
|
|
1686
|
+
```
|
|
1687
|
+
|
|
1688
|
+
**Key Point:** No mocking libraries needed! Effect.ts test layers provide real implementations.
|
|
1689
|
+
|
|
1690
|
+
---
|
|
1691
|
+
|
|
1692
|
+
## Migration Strategy
|
|
1693
|
+
|
|
1694
|
+
### Phase 1: Add AuthService Alongside Better Auth
|
|
1695
|
+
|
|
1696
|
+
Keep existing Better Auth, add AuthService:
|
|
1697
|
+
|
|
1698
|
+
```typescript
|
|
1699
|
+
// frontend/src/auth/config.ts
|
|
1700
|
+
|
|
1701
|
+
// OLD: Better Auth (keep for now)
|
|
1702
|
+
export const betterAuth = betterAuth({
|
|
1703
|
+
database: drizzleAdapter(db)
|
|
1704
|
+
})
|
|
1705
|
+
|
|
1706
|
+
// NEW: AuthService (add alongside)
|
|
1707
|
+
import { AuthService } from '@/services/AuthService'
|
|
1708
|
+
import { ClientLayer } from '@/services/ClientLayer'
|
|
1709
|
+
|
|
1710
|
+
// Use both in parallel during migration
|
|
1711
|
+
```
|
|
1712
|
+
|
|
1713
|
+
### Phase 2: Migrate Components One at a Time
|
|
1714
|
+
|
|
1715
|
+
```tsx
|
|
1716
|
+
// OLD: Better Auth
|
|
1717
|
+
import { useSession } from '@/auth/client'
|
|
1718
|
+
const session = useSession()
|
|
1719
|
+
|
|
1720
|
+
// NEW: AuthService + Effect.ts
|
|
1721
|
+
import { useEffectRunner } from '@/hooks/useEffectRunner'
|
|
1722
|
+
import { AuthService } from '@/services/AuthService'
|
|
1723
|
+
const { run } = useEffectRunner()
|
|
1724
|
+
const program = Effect.gen(function* () {
|
|
1725
|
+
const auth = yield* AuthService
|
|
1726
|
+
return yield* auth.getSession(token)
|
|
1727
|
+
})
|
|
1728
|
+
const session = await run(program)
|
|
1729
|
+
```
|
|
1730
|
+
|
|
1731
|
+
### Phase 3: Remove Better Auth
|
|
1732
|
+
|
|
1733
|
+
Once all components migrated, remove Better Auth dependencies.
|
|
1734
|
+
|
|
1735
|
+
---
|
|
1736
|
+
|
|
1737
|
+
## Summary
|
|
1738
|
+
|
|
1739
|
+
### What We Achieve
|
|
1740
|
+
|
|
1741
|
+
✅ **Users = Things (type: person)**
|
|
1742
|
+
- Works with all thing operations
|
|
1743
|
+
- Can have connections (relationships, org membership)
|
|
1744
|
+
- Can be actors in events (audit trail)
|
|
1745
|
+
- Can be embedded in knowledge (AI context)
|
|
1746
|
+
|
|
1747
|
+
✅ **Sessions = Connections (type: session)**
|
|
1748
|
+
- Real-time sync → revoke everywhere instantly
|
|
1749
|
+
- Automatic expiration → query only active
|
|
1750
|
+
- Analytics → count sessions, track patterns
|
|
1751
|
+
|
|
1752
|
+
✅ **Auth Events Logged**
|
|
1753
|
+
- Complete audit trail
|
|
1754
|
+
- Security analytics
|
|
1755
|
+
- User timeline
|
|
1756
|
+
|
|
1757
|
+
✅ **Effect.ts Integration**
|
|
1758
|
+
- Type-safe auth operations
|
|
1759
|
+
- Composable workflows
|
|
1760
|
+
- Consistent error handling
|
|
1761
|
+
- Easy testing with test layers
|
|
1762
|
+
|
|
1763
|
+
✅ **Backend-Agnostic**
|
|
1764
|
+
- AuthService uses DataProvider
|
|
1765
|
+
- Works with Convex, Supabase, WordPress, Notion
|
|
1766
|
+
- Swap backends by changing ONE line
|
|
1767
|
+
- Same auth code, different backend
|
|
1768
|
+
|
|
1769
|
+
✅ **Multi-Tenant by Default**
|
|
1770
|
+
- Users scoped to organizations
|
|
1771
|
+
- Sessions scoped to organizations
|
|
1772
|
+
- Data isolation automatic
|
|
1773
|
+
|
|
1774
|
+
### File Structure
|
|
1775
|
+
|
|
1776
|
+
```
|
|
1777
|
+
frontend/src/
|
|
1778
|
+
├── services/
|
|
1779
|
+
│ ├── AuthService.ts # Effect.ts auth service (uses DataProvider)
|
|
1780
|
+
│ ├── ThingService.ts # Generic thing operations
|
|
1781
|
+
│ ├── ConnectionService.ts # Generic connection operations
|
|
1782
|
+
│ └── ClientLayer.ts # Dependency injection
|
|
1783
|
+
├── providers/
|
|
1784
|
+
│ ├── DataProvider.ts # Universal interface
|
|
1785
|
+
│ ├── convex/
|
|
1786
|
+
│ │ └── ConvexProvider.ts # Convex implementation
|
|
1787
|
+
│ ├── supabase/
|
|
1788
|
+
│ │ └── SupabaseProvider.ts # Supabase implementation
|
|
1789
|
+
│ └── wordpress/
|
|
1790
|
+
│ └── WordPressProvider.ts # WordPress implementation
|
|
1791
|
+
├── components/
|
|
1792
|
+
│ └── auth/
|
|
1793
|
+
│ ├── SignUpForm.tsx # Uses AuthService + useEffectRunner
|
|
1794
|
+
│ ├── SignInForm.tsx # Uses AuthService + useEffectRunner
|
|
1795
|
+
│ └── OAuthButton.tsx # Uses AuthService + useEffectRunner
|
|
1796
|
+
├── hooks/
|
|
1797
|
+
│ └── useEffectRunner.ts # Run Effect programs in React
|
|
1798
|
+
└── middleware.ts # Session verification
|
|
1799
|
+
```
|
|
1800
|
+
|
|
1801
|
+
### Key Principles
|
|
1802
|
+
|
|
1803
|
+
1. **6-Dimension Ontology:** All auth data fits the complete reality model
|
|
1804
|
+
- Organizations → multi-tenant isolation
|
|
1805
|
+
- People → users with roles and authorization
|
|
1806
|
+
- Things → optional device tracking
|
|
1807
|
+
- Connections → sessions & OAuth links
|
|
1808
|
+
- Events → complete audit trail
|
|
1809
|
+
- Knowledge → AI-powered security
|
|
1810
|
+
|
|
1811
|
+
2. **Effect.ts Everywhere:** Type-safe, composable auth operations
|
|
1812
|
+
|
|
1813
|
+
3. **Backend-Agnostic:** DataProvider pattern works with any backend
|
|
1814
|
+
|
|
1815
|
+
4. **Multi-Tenant by Design:** Every operation scoped to organizationId
|
|
1816
|
+
|
|
1817
|
+
5. **Event-Driven:** All auth actions logged with actorId
|
|
1818
|
+
|
|
1819
|
+
6. **Real-Time:** Sessions as connections → instant updates everywhere
|
|
1820
|
+
|
|
1821
|
+
### Comparison
|
|
1822
|
+
|
|
1823
|
+
| Aspect | Better Auth (Traditional) | ONE 6-Dimension |
|
|
1824
|
+
|--------|---------------------------|------------------|
|
|
1825
|
+
| **Architecture** | 4 separate tables | 6 dimensions |
|
|
1826
|
+
| **Multi-Tenancy** | Manual implementation | Organizations (dimension 1) |
|
|
1827
|
+
| **Authorization** | Basic roles | People with roles (dimension 2) |
|
|
1828
|
+
| **Users** | Separate `user` table | Things (type: creator) |
|
|
1829
|
+
| **Devices** | Not tracked | Things (type: device) - optional |
|
|
1830
|
+
| **Sessions** | Separate `session` table | Connections (type: session) |
|
|
1831
|
+
| **OAuth** | Separate `account` table | Connections (type: oauth_account) |
|
|
1832
|
+
| **Audit Trail** | Not logged | Events (dimension 5) - complete |
|
|
1833
|
+
| **Security AI** | None | Knowledge (dimension 6) - patterns |
|
|
1834
|
+
| **Backend** | Database-specific adapters | Universal DataProvider |
|
|
1835
|
+
| **Error Handling** | Try/catch | Typed Effect errors |
|
|
1836
|
+
| **Testing** | Mock database | Effect test layers |
|
|
1837
|
+
| **Data Isolation** | Manual queries | Automatic (organizationId) |
|
|
1838
|
+
| **Analytics** | External tool | Built-in (events + knowledge) |
|
|
1839
|
+
|
|
1840
|
+
### Next Steps
|
|
1841
|
+
|
|
1842
|
+
1. **Implement AuthService** with Effect.ts + DataProvider
|
|
1843
|
+
2. **Create auth components** using useEffectRunner
|
|
1844
|
+
3. **Add session middleware** for protected routes
|
|
1845
|
+
4. **Test with mock DataProvider** (no database needed!)
|
|
1846
|
+
5. **Deploy** with chosen backend (Convex, Supabase, etc.)
|
|
1847
|
+
|
|
1848
|
+
---
|
|
1849
|
+
|
|
1850
|
+
**Better Auth + ONE 6-Dimension Ontology = Universal, Type-Safe, Multi-Tenant Authentication**
|
|
1851
|
+
|
|
1852
|
+
Organizations partition. People authorize. Things exist. Connections relate. Events record. Knowledge understands. Effect.ts everywhere. Works with any backend.
|