Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat(auth): add device authorization flow for CLI and external apps

Tin6f3f8c3ca83f
diff --git a/apps/api/drizzle/0023_cold_omega_red.sql b/apps/api/drizzle/0023_cold_omega_red.sql
new file mode 100644
index 000000000..c96de8588
--- /dev/null
+++ b/apps/api/drizzle/0023_cold_omega_red.sql
@@ -0,0 +1,17 @@
+CREATE TABLE "device_code" (
+ "id" text PRIMARY KEY NOT NULL,
+ "device_code" text NOT NULL,
+ "user_code" text NOT NULL,
+ "user_id" text,
+ "expires_at" timestamp NOT NULL,
+ "status" text NOT NULL,
+ "last_polled_at" timestamp,
+ "polling_interval" integer,
+ "client_id" text,
+ "scope" text
+);
+--> statement-breakpoint
+ALTER TABLE "device_code" ADD CONSTRAINT "device_code_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE cascade;--> statement-breakpoint
+CREATE UNIQUE INDEX "device_code_device_code_uidx" ON "device_code" USING btree ("device_code");--> statement-breakpoint
+CREATE UNIQUE INDEX "device_code_user_code_uidx" ON "device_code" USING btree ("user_code");--> statement-breakpoint
+CREATE INDEX "device_code_user_id_idx" ON "device_code" USING btree ("user_id");
\ No newline at end of file
diff --git a/apps/api/drizzle/meta/0023_snapshot.json b/apps/api/drizzle/meta/0023_snapshot.json
new file mode 100644
index 000000000..34997b0bd
--- /dev/null
+++ b/apps/api/drizzle/meta/0023_snapshot.json
@@ -0,0 +1,2783 @@
+{
+ "id": "ee695959-0cad-4f20-9219-7bcefd51ff6d",
+ "prevId": "5ad5fd49-df50-4bea-850e-f6d831397d0b",
+ "version": "7",
+ "dialect": "postgresql",
+ "tables": {
+ "public.account": {
+ "name": "account",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "account_id": {
+ "name": "account_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "provider_id": {
+ "name": "provider_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "access_token": {
+ "name": "access_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "refresh_token": {
+ "name": "refresh_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "id_token": {
+ "name": "id_token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "access_token_expires_at": {
+ "name": "access_token_expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "refresh_token_expires_at": {
+ "name": "refresh_token_expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "scope": {
+ "name": "scope",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "password": {
+ "name": "password",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {
+ "account_userId_idx": {
+ "name": "account_userId_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "account_user_id_user_id_fk": {
+ "name": "account_user_id_user_id_fk",
+ "tableFrom": "account",
+ "tableTo": "user",
+ "columnsFrom": ["user_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.activity": {
+ "name": "activity",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "task_id": {
+ "name": "task_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "type": {
+ "name": "type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "content": {
+ "name": "content",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "event_data": {
+ "name": "event_data",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "external_user_name": {
+ "name": "external_user_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "external_user_avatar": {
+ "name": "external_user_avatar",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "external_source": {
+ "name": "external_source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "external_url": {
+ "name": "external_url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {
+ "activity_task_id_idx": {
+ "name": "activity_task_id_idx",
+ "columns": [
+ {
+ "expression": "task_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "activity_task_id_task_id_fk": {
+ "name": "activity_task_id_task_id_fk",
+ "tableFrom": "activity",
+ "tableTo": "task",
+ "columnsFrom": ["task_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "activity_user_id_user_id_fk": {
+ "name": "activity_user_id_user_id_fk",
+ "tableFrom": "activity",
+ "tableTo": "user",
+ "columnsFrom": ["user_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "activity_task_external_source_external_url_unique": {
+ "name": "activity_task_external_source_external_url_unique",
+ "nullsNotDistinct": false,
+ "columns": ["task_id", "external_source", "external_url"]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.apikey": {
+ "name": "apikey",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "config_id": {
+ "name": "config_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'default'"
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "start": {
+ "name": "start",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "reference_id": {
+ "name": "reference_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "prefix": {
+ "name": "prefix",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "key": {
+ "name": "key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "refill_interval": {
+ "name": "refill_interval",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "refill_amount": {
+ "name": "refill_amount",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "last_refill_at": {
+ "name": "last_refill_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "enabled": {
+ "name": "enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false,
+ "default": true
+ },
+ "rate_limit_enabled": {
+ "name": "rate_limit_enabled",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false,
+ "default": true
+ },
+ "rate_limit_time_window": {
+ "name": "rate_limit_time_window",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "default": 86400000
+ },
+ "rate_limit_max": {
+ "name": "rate_limit_max",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "default": 10
+ },
+ "request_count": {
+ "name": "request_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "default": 0
+ },
+ "remaining": {
+ "name": "remaining",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "last_request": {
+ "name": "last_request",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "permissions": {
+ "name": "permissions",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "metadata": {
+ "name": "metadata",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {
+ "apikey_configId_idx": {
+ "name": "apikey_configId_idx",
+ "columns": [
+ {
+ "expression": "config_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "apikey_key_idx": {
+ "name": "apikey_key_idx",
+ "columns": [
+ {
+ "expression": "key",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "apikey_referenceId_idx": {
+ "name": "apikey_referenceId_idx",
+ "columns": [
+ {
+ "expression": "reference_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "apikey_userId_idx": {
+ "name": "apikey_userId_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "apikey_reference_id_user_id_fk": {
+ "name": "apikey_reference_id_user_id_fk",
+ "tableFrom": "apikey",
+ "tableTo": "user",
+ "columnsFrom": ["reference_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "apikey_user_id_user_id_fk": {
+ "name": "apikey_user_id_user_id_fk",
+ "tableFrom": "apikey",
+ "tableTo": "user",
+ "columnsFrom": ["user_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.asset": {
+ "name": "asset",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "task_id": {
+ "name": "task_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "activity_id": {
+ "name": "activity_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "object_key": {
+ "name": "object_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "filename": {
+ "name": "filename",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "mime_type": {
+ "name": "mime_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "size": {
+ "name": "size",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "kind": {
+ "name": "kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'image'"
+ },
+ "surface": {
+ "name": "surface",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'description'"
+ },
+ "created_by": {
+ "name": "created_by",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "asset_workspaceId_idx": {
+ "name": "asset_workspaceId_idx",
+ "columns": [
+ {
+ "expression": "workspace_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "asset_projectId_idx": {
+ "name": "asset_projectId_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "asset_taskId_idx": {
+ "name": "asset_taskId_idx",
+ "columns": [
+ {
+ "expression": "task_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "asset_activityId_idx": {
+ "name": "asset_activityId_idx",
+ "columns": [
+ {
+ "expression": "activity_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "asset_workspace_id_workspace_id_fk": {
+ "name": "asset_workspace_id_workspace_id_fk",
+ "tableFrom": "asset",
+ "tableTo": "workspace",
+ "columnsFrom": ["workspace_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "asset_project_id_project_id_fk": {
+ "name": "asset_project_id_project_id_fk",
+ "tableFrom": "asset",
+ "tableTo": "project",
+ "columnsFrom": ["project_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "asset_task_id_task_id_fk": {
+ "name": "asset_task_id_task_id_fk",
+ "tableFrom": "asset",
+ "tableTo": "task",
+ "columnsFrom": ["task_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "asset_activity_id_activity_id_fk": {
+ "name": "asset_activity_id_activity_id_fk",
+ "tableFrom": "asset",
+ "tableTo": "activity",
+ "columnsFrom": ["activity_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "asset_created_by_user_id_fk": {
+ "name": "asset_created_by_user_id_fk",
+ "tableFrom": "asset",
+ "tableTo": "user",
+ "columnsFrom": ["created_by"],
+ "columnsTo": ["id"],
+ "onDelete": "set null",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "asset_object_key_unique": {
+ "name": "asset_object_key_unique",
+ "nullsNotDistinct": false,
+ "columns": ["object_key"]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.column": {
+ "name": "column",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "slug": {
+ "name": "slug",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "position": {
+ "name": "position",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "default": 0
+ },
+ "icon": {
+ "name": "icon",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "color": {
+ "name": "color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "is_final": {
+ "name": "is_final",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true,
+ "default": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "column_projectId_idx": {
+ "name": "column_projectId_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "column_project_id_project_id_fk": {
+ "name": "column_project_id_project_id_fk",
+ "tableFrom": "column",
+ "tableTo": "project",
+ "columnsFrom": ["project_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.comment": {
+ "name": "comment",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "task_id": {
+ "name": "task_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "content": {
+ "name": "content",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "comment_task_idx": {
+ "name": "comment_task_idx",
+ "columns": [
+ {
+ "expression": "task_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "comment_user_idx": {
+ "name": "comment_user_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "comment_task_id_task_id_fk": {
+ "name": "comment_task_id_task_id_fk",
+ "tableFrom": "comment",
+ "tableTo": "task",
+ "columnsFrom": ["task_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "comment_user_id_user_id_fk": {
+ "name": "comment_user_id_user_id_fk",
+ "tableFrom": "comment",
+ "tableTo": "user",
+ "columnsFrom": ["user_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.device_code": {
+ "name": "device_code",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "device_code": {
+ "name": "device_code",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_code": {
+ "name": "user_code",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "last_polled_at": {
+ "name": "last_polled_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "polling_interval": {
+ "name": "polling_interval",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "client_id": {
+ "name": "client_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "scope": {
+ "name": "scope",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {
+ "device_code_device_code_uidx": {
+ "name": "device_code_device_code_uidx",
+ "columns": [
+ {
+ "expression": "device_code",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "device_code_user_code_uidx": {
+ "name": "device_code_user_code_uidx",
+ "columns": [
+ {
+ "expression": "user_code",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "device_code_user_id_idx": {
+ "name": "device_code_user_id_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "device_code_user_id_user_id_fk": {
+ "name": "device_code_user_id_user_id_fk",
+ "tableFrom": "device_code",
+ "tableTo": "user",
+ "columnsFrom": ["user_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.external_link": {
+ "name": "external_link",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "task_id": {
+ "name": "task_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "integration_id": {
+ "name": "integration_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "resource_type": {
+ "name": "resource_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "external_id": {
+ "name": "external_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "url": {
+ "name": "url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "metadata": {
+ "name": "metadata",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "external_link_taskId_idx": {
+ "name": "external_link_taskId_idx",
+ "columns": [
+ {
+ "expression": "task_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "external_link_integrationId_idx": {
+ "name": "external_link_integrationId_idx",
+ "columns": [
+ {
+ "expression": "integration_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "external_link_externalId_idx": {
+ "name": "external_link_externalId_idx",
+ "columns": [
+ {
+ "expression": "external_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "external_link_resourceType_idx": {
+ "name": "external_link_resourceType_idx",
+ "columns": [
+ {
+ "expression": "resource_type",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "external_link_task_id_task_id_fk": {
+ "name": "external_link_task_id_task_id_fk",
+ "tableFrom": "external_link",
+ "tableTo": "task",
+ "columnsFrom": ["task_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "external_link_integration_id_integration_id_fk": {
+ "name": "external_link_integration_id_integration_id_fk",
+ "tableFrom": "external_link",
+ "tableTo": "integration",
+ "columnsFrom": ["integration_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.github_integration": {
+ "name": "github_integration",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "repository_owner": {
+ "name": "repository_owner",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "repository_name": {
+ "name": "repository_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "installation_id": {
+ "name": "installation_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "is_active": {
+ "name": "is_active",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false,
+ "default": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "github_integration_project_id_project_id_fk": {
+ "name": "github_integration_project_id_project_id_fk",
+ "tableFrom": "github_integration",
+ "tableTo": "project",
+ "columnsFrom": ["project_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "github_integration_project_id_unique": {
+ "name": "github_integration_project_id_unique",
+ "nullsNotDistinct": false,
+ "columns": ["project_id"]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.integration": {
+ "name": "integration",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "type": {
+ "name": "type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "config": {
+ "name": "config",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "is_active": {
+ "name": "is_active",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false,
+ "default": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "integration_projectId_idx": {
+ "name": "integration_projectId_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "integration_type_idx": {
+ "name": "integration_type_idx",
+ "columns": [
+ {
+ "expression": "type",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "integration_project_id_project_id_fk": {
+ "name": "integration_project_id_project_id_fk",
+ "tableFrom": "integration",
+ "tableTo": "project",
+ "columnsFrom": ["project_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "integration_project_type_unique": {
+ "name": "integration_project_type_unique",
+ "nullsNotDistinct": false,
+ "columns": ["project_id", "type"]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.invitation": {
+ "name": "invitation",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "team_id": {
+ "name": "team_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'pending'"
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "inviter_id": {
+ "name": "inviter_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {
+ "invitation_workspaceId_idx": {
+ "name": "invitation_workspaceId_idx",
+ "columns": [
+ {
+ "expression": "workspace_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "invitation_email_idx": {
+ "name": "invitation_email_idx",
+ "columns": [
+ {
+ "expression": "email",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "invitation_workspace_id_workspace_id_fk": {
+ "name": "invitation_workspace_id_workspace_id_fk",
+ "tableFrom": "invitation",
+ "tableTo": "workspace",
+ "columnsFrom": ["workspace_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "invitation_inviter_id_user_id_fk": {
+ "name": "invitation_inviter_id_user_id_fk",
+ "tableFrom": "invitation",
+ "tableTo": "user",
+ "columnsFrom": ["inviter_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.label": {
+ "name": "label",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "color": {
+ "name": "color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "task_id": {
+ "name": "task_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {
+ "label_task_id_idx": {
+ "name": "label_task_id_idx",
+ "columns": [
+ {
+ "expression": "task_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "label_workspace_id_idx": {
+ "name": "label_workspace_id_idx",
+ "columns": [
+ {
+ "expression": "workspace_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "label_workspace_name_unique": {
+ "name": "label_workspace_name_unique",
+ "columns": [
+ {
+ "expression": "workspace_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ },
+ {
+ "expression": "name",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": true,
+ "where": "\"label\".\"task_id\" is null",
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "label_task_id_task_id_fk": {
+ "name": "label_task_id_task_id_fk",
+ "tableFrom": "label",
+ "tableTo": "task",
+ "columnsFrom": ["task_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "label_workspace_id_workspace_id_fk": {
+ "name": "label_workspace_id_workspace_id_fk",
+ "tableFrom": "label",
+ "tableTo": "workspace",
+ "columnsFrom": ["workspace_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "label_task_name_unique": {
+ "name": "label_task_name_unique",
+ "nullsNotDistinct": false,
+ "columns": ["task_id", "name"]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.notification": {
+ "name": "notification",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "content": {
+ "name": "content",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "type": {
+ "name": "type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'info'"
+ },
+ "event_data": {
+ "name": "event_data",
+ "type": "jsonb",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "is_read": {
+ "name": "is_read",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false,
+ "default": false
+ },
+ "resource_id": {
+ "name": "resource_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "resource_type": {
+ "name": "resource_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp with time zone",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "notification_user_id_user_id_fk": {
+ "name": "notification_user_id_user_id_fk",
+ "tableFrom": "notification",
+ "tableTo": "user",
+ "columnsFrom": ["user_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.project": {
+ "name": "project",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "slug": {
+ "name": "slug",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "icon": {
+ "name": "icon",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "default": "'Layout'"
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "is_public": {
+ "name": "is_public",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false,
+ "default": false
+ },
+ "archived_at": {
+ "name": "archived_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "project_workspace_id_workspace_id_fk": {
+ "name": "project_workspace_id_workspace_id_fk",
+ "tableFrom": "project",
+ "tableTo": "workspace",
+ "columnsFrom": ["workspace_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.session": {
+ "name": "session",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "token": {
+ "name": "token",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "ip_address": {
+ "name": "ip_address",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "user_agent": {
+ "name": "user_agent",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "active_organization_id": {
+ "name": "active_organization_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "active_team_id": {
+ "name": "active_team_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {
+ "session_userId_idx": {
+ "name": "session_userId_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "session_user_id_user_id_fk": {
+ "name": "session_user_id_user_id_fk",
+ "tableFrom": "session",
+ "tableTo": "user",
+ "columnsFrom": ["user_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "session_token_unique": {
+ "name": "session_token_unique",
+ "nullsNotDistinct": false,
+ "columns": ["token"]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.task_relation": {
+ "name": "task_relation",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "source_task_id": {
+ "name": "source_task_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "target_task_id": {
+ "name": "target_task_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "relation_type": {
+ "name": "relation_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "task_relation_source_idx": {
+ "name": "task_relation_source_idx",
+ "columns": [
+ {
+ "expression": "source_task_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "task_relation_target_idx": {
+ "name": "task_relation_target_idx",
+ "columns": [
+ {
+ "expression": "target_task_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "task_relation_source_task_id_task_id_fk": {
+ "name": "task_relation_source_task_id_task_id_fk",
+ "tableFrom": "task_relation",
+ "tableTo": "task",
+ "columnsFrom": ["source_task_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "task_relation_target_task_id_task_id_fk": {
+ "name": "task_relation_target_task_id_task_id_fk",
+ "tableFrom": "task_relation",
+ "tableTo": "task",
+ "columnsFrom": ["target_task_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.task": {
+ "name": "task",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "position": {
+ "name": "position",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "default": 0
+ },
+ "number": {
+ "name": "number",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "default": 1
+ },
+ "assignee_id": {
+ "name": "assignee_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'to-do'"
+ },
+ "column_id": {
+ "name": "column_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "priority": {
+ "name": "priority",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "default": "'low'"
+ },
+ "start_date": {
+ "name": "start_date",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "due_date": {
+ "name": "due_date",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "task_projectId_idx": {
+ "name": "task_projectId_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "task_project_id_project_id_fk": {
+ "name": "task_project_id_project_id_fk",
+ "tableFrom": "task",
+ "tableTo": "project",
+ "columnsFrom": ["project_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "task_assignee_id_user_id_fk": {
+ "name": "task_assignee_id_user_id_fk",
+ "tableFrom": "task",
+ "tableTo": "user",
+ "columnsFrom": ["assignee_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "task_column_id_column_id_fk": {
+ "name": "task_column_id_column_id_fk",
+ "tableFrom": "task",
+ "tableTo": "column",
+ "columnsFrom": ["column_id"],
+ "columnsTo": ["id"],
+ "onDelete": "set null",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "task_project_number_unique": {
+ "name": "task_project_number_unique",
+ "nullsNotDistinct": false,
+ "columns": ["project_id", "number"]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.team": {
+ "name": "team",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {
+ "team_workspaceId_idx": {
+ "name": "team_workspaceId_idx",
+ "columns": [
+ {
+ "expression": "workspace_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "team_workspace_id_workspace_id_fk": {
+ "name": "team_workspace_id_workspace_id_fk",
+ "tableFrom": "team",
+ "tableTo": "workspace",
+ "columnsFrom": ["workspace_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.team_member": {
+ "name": "team_member",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "team_id": {
+ "name": "team_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ }
+ },
+ "indexes": {
+ "teamMember_teamId_idx": {
+ "name": "teamMember_teamId_idx",
+ "columns": [
+ {
+ "expression": "team_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "teamMember_userId_idx": {
+ "name": "teamMember_userId_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "team_member_team_id_team_id_fk": {
+ "name": "team_member_team_id_team_id_fk",
+ "tableFrom": "team_member",
+ "tableTo": "team",
+ "columnsFrom": ["team_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "team_member_user_id_user_id_fk": {
+ "name": "team_member_user_id_user_id_fk",
+ "tableFrom": "team_member",
+ "tableTo": "user",
+ "columnsFrom": ["user_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.time_entry": {
+ "name": "time_entry",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "task_id": {
+ "name": "task_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "start_time": {
+ "name": "start_time",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "end_time": {
+ "name": "end_time",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "duration": {
+ "name": "duration",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "default": 0
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "time_entry_task_id_task_id_fk": {
+ "name": "time_entry_task_id_task_id_fk",
+ "tableFrom": "time_entry",
+ "tableTo": "task",
+ "columnsFrom": ["task_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "time_entry_user_id_user_id_fk": {
+ "name": "time_entry_user_id_user_id_fk",
+ "tableFrom": "time_entry",
+ "tableTo": "user",
+ "columnsFrom": ["user_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.user": {
+ "name": "user",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "email": {
+ "name": "email",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "email_verified": {
+ "name": "email_verified",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "image": {
+ "name": "image",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "locale": {
+ "name": "locale",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "is_anonymous": {
+ "name": "is_anonymous",
+ "type": "boolean",
+ "primaryKey": false,
+ "notNull": false,
+ "default": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "user_email_unique": {
+ "name": "user_email_unique",
+ "nullsNotDistinct": false,
+ "columns": ["email"]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.verification": {
+ "name": "verification",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "identifier": {
+ "name": "identifier",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "value": {
+ "name": "value",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "verification_identifier_idx": {
+ "name": "verification_identifier_idx",
+ "columns": [
+ {
+ "expression": "identifier",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.workflow_rule": {
+ "name": "workflow_rule",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "project_id": {
+ "name": "project_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "integration_type": {
+ "name": "integration_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "event_type": {
+ "name": "event_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "column_id": {
+ "name": "column_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "now()"
+ }
+ },
+ "indexes": {
+ "workflow_rule_projectId_idx": {
+ "name": "workflow_rule_projectId_idx",
+ "columns": [
+ {
+ "expression": "project_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "workflow_rule_project_id_project_id_fk": {
+ "name": "workflow_rule_project_id_project_id_fk",
+ "tableFrom": "workflow_rule",
+ "tableTo": "project",
+ "columnsFrom": ["project_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ },
+ "workflow_rule_column_id_column_id_fk": {
+ "name": "workflow_rule_column_id_column_id_fk",
+ "tableFrom": "workflow_rule",
+ "tableTo": "column",
+ "columnsFrom": ["column_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "cascade"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.workspace": {
+ "name": "workspace",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "slug": {
+ "name": "slug",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "logo": {
+ "name": "logo",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "metadata": {
+ "name": "metadata",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {
+ "workspace_slug_unique": {
+ "name": "workspace_slug_unique",
+ "nullsNotDistinct": false,
+ "columns": ["slug"]
+ }
+ },
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ },
+ "public.workspace_member": {
+ "name": "workspace_member",
+ "schema": "",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true
+ },
+ "workspace_id": {
+ "name": "workspace_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "default": "'member'"
+ },
+ "joined_at": {
+ "name": "joined_at",
+ "type": "timestamp",
+ "primaryKey": false,
+ "notNull": true
+ }
+ },
+ "indexes": {
+ "workspace_member_workspaceId_idx": {
+ "name": "workspace_member_workspaceId_idx",
+ "columns": [
+ {
+ "expression": "workspace_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ },
+ "workspace_member_userId_idx": {
+ "name": "workspace_member_userId_idx",
+ "columns": [
+ {
+ "expression": "user_id",
+ "isExpression": false,
+ "asc": true,
+ "nulls": "last"
+ }
+ ],
+ "isUnique": false,
+ "concurrently": false,
+ "method": "btree",
+ "with": {}
+ }
+ },
+ "foreignKeys": {
+ "workspace_member_workspace_id_workspace_id_fk": {
+ "name": "workspace_member_workspace_id_workspace_id_fk",
+ "tableFrom": "workspace_member",
+ "tableTo": "workspace",
+ "columnsFrom": ["workspace_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "workspace_member_user_id_user_id_fk": {
+ "name": "workspace_member_user_id_user_id_fk",
+ "tableFrom": "workspace_member",
+ "tableTo": "user",
+ "columnsFrom": ["user_id"],
+ "columnsTo": ["id"],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "policies": {},
+ "checkConstraints": {},
+ "isRLSEnabled": false
+ }
+ },
+ "enums": {},
+ "schemas": {},
+ "sequences": {},
+ "roles": {},
+ "policies": {},
+ "views": {},
+ "_meta": {
+ "columns": {},
+ "schemas": {},
+ "tables": {}
+ }
+}
diff --git a/apps/api/drizzle/meta/_journal.json b/apps/api/drizzle/meta/_journal.json
index 19fc12d3f..e91bde4b7 100644
--- a/apps/api/drizzle/meta/_journal.json
+++ b/apps/api/drizzle/meta/_journal.json
@@ -162,6 +162,13 @@
"when": 1774944216644,
"tag": "0022_material_electro",
"breakpoints": true
+ },
+ {
+ "idx": 23,
+ "version": "7",
+ "when": 1775215568801,
+ "tag": "0023_cold_omega_red",
+ "breakpoints": true
}
]
}
diff --git a/apps/api/src/auth.ts b/apps/api/src/auth.ts
index 0e1511be1..50384e085 100644
--- a/apps/api/src/auth.ts
+++ b/apps/api/src/auth.ts
@@ -10,6 +10,8 @@ import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { APIError, createAuthMiddleware } from "better-auth/api";
import {
anonymous,
+ bearer,
+ deviceAuthorization,
emailOTP,
genericOAuth,
lastLoginMethod,
@@ -98,6 +100,24 @@ function getAuthEmailCopy(locale?: string | null) {
};
}
+function getDeviceAuthClientIds(): Set<string> {
+ const raw = process.env.DEVICE_AUTH_CLIENT_IDS?.trim();
+ if (raw) {
+ return new Set(
+ raw
+ .split(",")
+ .map((s) => s.trim())
+ .filter(Boolean),
+ );
+ }
+ return new Set(["kaneo-cli"]);
+}
+
+function getDeviceAuthVerificationUri(): string {
+ const base = clientUrl.replace(/\/$/, "");
+ return `${base}/device`;
+}
+
function getInvitationEmailSubject(
locale: string | null,
inviterName: string,
@@ -127,6 +147,7 @@ export const auth = betterAuth({
team: schema.teamTable,
teamMember: schema.teamMemberTable,
apikey: schema.apikeyTable,
+ deviceCode: schema.deviceCodeTable,
},
}),
user: {
@@ -302,6 +323,7 @@ export const auth = betterAuth({
},
],
}),
+ bearer(),
apiKey({
enableSessionForAPIKeys: true,
apiKeyHeaders: "x-api-key",
@@ -311,6 +333,11 @@ export const auth = betterAuth({
timeWindow: 60 * 1000,
},
}),
+ deviceAuthorization({
+ verificationUri: getDeviceAuthVerificationUri(),
+ validateClient: async (clientId) =>
+ getDeviceAuthClientIds().has(clientId),
+ }),
openAPI(),
],
session: {
diff --git a/apps/api/src/database/index.ts b/apps/api/src/database/index.ts
index 35a026a3a..ce673a2db 100644
--- a/apps/api/src/database/index.ts
+++ b/apps/api/src/database/index.ts
@@ -34,6 +34,7 @@ import {
assetTable,
columnTable,
commentTable,
+ deviceCodeTable,
externalLinkTable,
githubIntegrationTable,
integrationTable,
@@ -69,6 +70,7 @@ export const schema = {
apikeyTable,
columnTable,
commentTable,
+ deviceCodeTable,
externalLinkTable,
githubIntegrationTable,
integrationTable,
diff --git a/apps/api/src/database/schema.ts b/apps/api/src/database/schema.ts
index 517dd0d33..b226cddb4 100644
--- a/apps/api/src/database/schema.ts
+++ b/apps/api/src/database/schema.ts
@@ -657,6 +657,32 @@ export const apikeyTable = pgTable(
],
);
+export const deviceCodeTable = pgTable(
+ "device_code",
+ {
+ id: text("id")
+ .$defaultFn(() => createId())
+ .primaryKey(),
+ deviceCode: text("device_code").notNull(),
+ userCode: text("user_code").notNull(),
+ userId: text("user_id").references(() => userTable.id, {
+ onDelete: "cascade",
+ onUpdate: "cascade",
+ }),
+ expiresAt: timestamp("expires_at", { mode: "date" }).notNull(),
+ status: text("status").notNull(),
+ lastPolledAt: timestamp("last_polled_at", { mode: "date" }),
+ pollingInterval: integer("polling_interval"),
+ clientId: text("client_id"),
+ scope: text("scope"),
+ },
+ (table) => [
+ uniqueIndex("device_code_device_code_uidx").on(table.deviceCode),
+ uniqueIndex("device_code_user_code_uidx").on(table.userCode),
+ index("device_code_user_id_idx").on(table.userId),
+ ],
+);
+
// Auth-schema compatible aliases in schema.ts
export const user = userTable;
export const session = sessionTable;
@@ -668,6 +694,7 @@ export const teamMember = teamMemberTable;
export const workspace_member = workspaceUserTable;
export const invitation = invitationTable;
export const apikey = apikeyTable;
+export const deviceCode = deviceCodeTable;
// Auth-schema compatible relation exports in schema.ts
export const userRelations = relations(user, ({ many }) => ({
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index d84341484..d57a7f2f3 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -41,6 +41,10 @@ import task from "./task";
import taskRelation from "./task-relation";
import telegramIntegration from "./telegram-integration";
import timeEntry from "./time-entry";
+import {
+ authenticateApiRequest,
+ resolveAssetBearerOrCookie,
+} from "./utils/authenticate-api-request";
import { getInvitationDetails } from "./utils/check-registration-allowed";
import { migrateApiKeyReferenceId } from "./utils/migrate-apikey-reference-id";
import { migrateSessionColumn } from "./utils/migrate-session-column";
@@ -56,7 +60,6 @@ import {
normalizeOrganizationAuthOperations,
} from "./utils/openapi-spec";
import { validateWorkspaceAccess } from "./utils/validate-workspace-access";
-import { verifyApiKey } from "./utils/verify-api-key";
import workflowRule from "./workflow-rule";
import workspace from "./workspace";
@@ -219,29 +222,7 @@ export function createApp() {
throw new HTTPException(404, { message: "Asset not found" });
}
- const authHeader = c.req.header("Authorization");
- const bearerToken = authHeader?.startsWith("Bearer ")
- ? authHeader.substring(7).replace(/\s+/g, "").trim()
- : null;
-
- let userId = "";
- let apiKeyId: string | undefined;
-
- if (bearerToken) {
- const result = await verifyApiKey(bearerToken);
-
- if (result?.valid && result.key) {
- userId = result.key.userId;
- apiKeyId = result.key.id;
- } else {
- throw new HTTPException(401, { message: "Invalid API key" });
- }
- } else {
- const session = await auth.api.getSession({
- headers: c.req.raw.headers,
- });
- userId = session?.user?.id || "";
- }
+ const { userId, apiKeyId } = await resolveAssetBearerOrCookie(c);
if (userId) {
await validateWorkspaceAccess(userId, asset.workspaceId, apiKeyId);
@@ -295,7 +276,7 @@ export function createApp() {
bearerAuth: {
type: "http",
scheme: "bearer",
- description: "API Key authentication",
+ description: "API key or session token (Bearer)",
},
},
},
@@ -334,6 +315,26 @@ export function createApp() {
);
});
+ // Better Auth serves GET /auth/device as JSON. Browsers that open the API URL
+ // directly expect a page — redirect full document navigations to the web app.
+ api.get("/auth/device", async (c) => {
+ const userCode = c.req.query("user_code");
+ const secFetchDest = c.req.header("Sec-Fetch-Dest");
+ const forceUiRedirect = c.req.query("ui") === "1";
+ // Top-level browser tab / address bar (not `fetch()` / XHR from the SPA).
+ // Optional `ui=1` forces redirect when Sec-Fetch-* headers are missing (e.g. some clients).
+ if (userCode && (forceUiRedirect || secFetchDest === "document")) {
+ const clientUrl = (
+ process.env.KANEO_CLIENT_URL || "http://localhost:5173"
+ ).replace(/\/$/, "");
+ return c.redirect(
+ `${clientUrl}/device?user_code=${encodeURIComponent(userCode)}`,
+ 302,
+ );
+ }
+ return auth.handler(c.req.raw);
+ });
+
api.on(["POST", "GET", "PUT", "DELETE"], "/auth/*", (c) => {
const authHeader = c.req.header("Authorization");
@@ -357,47 +358,15 @@ export function createApp() {
});
api.use("*", async (c, next) => {
- const authHeader = c.req.header("Authorization");
- if (authHeader?.startsWith("Bearer ")) {
- const apiKey = authHeader.substring(7).replace(/\s+/g, "").trim();
-
- try {
- const result = await verifyApiKey(apiKey);
-
- if (result?.valid && result.key) {
- c.set("userId", result.key.userId);
- c.set("user", null);
- c.set("session", null);
- c.set("apiKey", {
- id: result.key.id,
- userId: result.key.userId,
- enabled: result.key.enabled,
- });
- return next();
- }
-
- throw new HTTPException(401, { message: "Invalid API key" });
- } catch (error) {
- if (error instanceof HTTPException) {
- throw error;
- }
- console.error("API key verification failed:", error);
- throw new HTTPException(401, {
- message: "API key verification failed",
- });
+ try {
+ await authenticateApiRequest(c);
+ } catch (error) {
+ if (error instanceof HTTPException) {
+ throw error;
}
- }
-
- const session = await auth.api.getSession({ headers: c.req.raw.headers });
- c.set("user", session?.user || null);
- c.set("session", session?.session || null);
- c.set("userId", session?.user?.id || "");
- c.set("userEmail", session?.user?.email || "");
-
- if (!session?.user) {
+ console.error("API authentication failed:", error);
throw new HTTPException(401, { message: "Unauthorized" });
}
-
return next();
});
diff --git a/apps/api/src/utils/authenticate-api-request.ts b/apps/api/src/utils/authenticate-api-request.ts
new file mode 100644
index 000000000..34ee2b437
--- /dev/null
+++ b/apps/api/src/utils/authenticate-api-request.ts
@@ -0,0 +1,79 @@
+import type { Context } from "hono";
+import { HTTPException } from "hono/http-exception";
+import { auth } from "../auth";
+import { verifyApiKey } from "./verify-api-key";
+
+async function getSessionFromBearerOnlyHeaders(c: Context) {
+ const headers = new Headers(c.req.raw.headers);
+ headers.delete("cookie");
+
+ return auth.api.getSession({ headers });
+}
+
+export async function authenticateApiRequest(c: Context): Promise<void> {
+ const authHeader = c.req.header("Authorization");
+ if (authHeader?.startsWith("Bearer ")) {
+ const token = authHeader.substring(7).replace(/\s+/g, "").trim();
+ const apiKeyResult = await verifyApiKey(token);
+ if (apiKeyResult?.valid && apiKeyResult.key) {
+ const key = apiKeyResult.key;
+ c.set("userId", key.userId);
+ c.set("user", null);
+ c.set("session", null);
+ c.set("apiKey", {
+ id: key.id,
+ userId: key.userId,
+ enabled: key.enabled,
+ });
+ return;
+ }
+ const sessionResult = await getSessionFromBearerOnlyHeaders(c);
+ if (sessionResult?.user && sessionResult.session) {
+ c.set("user", sessionResult.user);
+ c.set("session", sessionResult.session);
+ c.set("userId", sessionResult.user.id);
+ c.set("userEmail", sessionResult.user.email ?? "");
+ return;
+ }
+ throw new HTTPException(401, { message: "Unauthorized" });
+ }
+
+ const sessionResult = await auth.api.getSession({
+ headers: c.req.raw.headers,
+ });
+ c.set("user", sessionResult?.user ?? null);
+ c.set("session", sessionResult?.session ?? null);
+ c.set("userId", sessionResult?.user?.id ?? "");
+ c.set("userEmail", sessionResult?.user?.email ?? "");
+
+ if (!sessionResult?.user) {
+ throw new HTTPException(401, { message: "Unauthorized" });
+ }
+}
+
+export async function resolveAssetBearerOrCookie(c: Context): Promise<{
+ userId: string;
+ apiKeyId?: string;
+}> {
+ const authHeader = c.req.header("Authorization");
+ if (authHeader?.startsWith("Bearer ")) {
+ const token = authHeader.substring(7).replace(/\s+/g, "").trim();
+ const apiKeyResult = await verifyApiKey(token);
+ if (apiKeyResult?.valid && apiKeyResult.key) {
+ return {
+ userId: apiKeyResult.key.userId,
+ apiKeyId: apiKeyResult.key.id,
+ };
+ }
+ const sessionResult = await getSessionFromBearerOnlyHeaders(c);
+ if (sessionResult?.user?.id) {
+ return { userId: sessionResult.user.id };
+ }
+ throw new HTTPException(401, { message: "Unauthorized" });
+ }
+
+ const sessionResult = await auth.api.getSession({
+ headers: c.req.raw.headers,
+ });
+ return { userId: sessionResult?.user?.id ?? "" };
+}
diff --git a/apps/web/src/components/auth/otp-sign-in-form.tsx b/apps/web/src/components/auth/otp-sign-in-form.tsx
index 6491c1672..8bde15b33 100644
--- a/apps/web/src/components/auth/otp-sign-in-form.tsx
+++ b/apps/web/src/components/auth/otp-sign-in-form.tsx
@@ -20,6 +20,7 @@ import { toast } from "@/lib/toast";
type OtpSignInFormProps = {
invitationId?: string;
defaultEmail?: string;
+ redirect?: string;
onSuccess?: () => void;
};
@@ -32,6 +33,7 @@ type EmailFormValues = z.infer<typeof emailSchema>;
export function OtpSignInForm({
invitationId,
defaultEmail,
+ redirect,
}: OtpSignInFormProps) {
const { t } = useTranslation();
const [isPending, setIsPending] = useState(false);
@@ -60,6 +62,7 @@ export function OtpSignInForm({
const searchParams = new URLSearchParams({
email: data.email,
...(invitationId && { invitationId }),
+ ...(redirect && { redirect }),
});
history.push(`/auth/verify-otp?${searchParams.toString()}`);
} finally {
diff --git a/apps/web/src/lib/auth-client.ts b/apps/web/src/lib/auth-client.ts
index 8032429b5..30c9928dc 100644
--- a/apps/web/src/lib/auth-client.ts
+++ b/apps/web/src/lib/auth-client.ts
@@ -1,6 +1,7 @@
import { apiKeyClient } from "@better-auth/api-key/client";
import {
anonymousClient,
+ deviceAuthorizationClient,
emailOTPClient,
genericOAuthClient,
inferAdditionalFields,
@@ -38,6 +39,7 @@ export const authClient = createAuthClient({
},
}),
genericOAuthClient(),
+ deviceAuthorizationClient(),
apiKeyClient(),
inferAdditionalFields({
user: {
diff --git a/apps/web/src/routeTree.gen.ts b/apps/web/src/routeTree.gen.ts
index 6b17e1dc3..50cb07a8e 100644
--- a/apps/web/src/routeTree.gen.ts
+++ b/apps/web/src/routeTree.gen.ts
@@ -10,10 +10,13 @@
import { Route as rootRouteImport } from './routes/__root'
import { Route as TestErrorRouteImport } from './routes/test-error'
+import { Route as DeviceRouteImport } from './routes/device'
import { Route as AuthRouteImport } from './routes/auth'
import { Route as LayoutRouteImport } from './routes/_layout'
import { Route as IndexRouteImport } from './routes/index'
+import { Route as DeviceIndexRouteImport } from './routes/device/index'
import { Route as PublicProjectProjectIdRouteImport } from './routes/public-project.$projectId'
+import { Route as DeviceApproveRouteImport } from './routes/device/approve'
import { Route as AuthVerifyOtpRouteImport } from './routes/auth/verify-otp'
import { Route as AuthSignUpRouteImport } from './routes/auth/sign-up'
import { Route as AuthSignInRouteImport } from './routes/auth/sign-in'
@@ -54,6 +57,11 @@ const TestErrorRoute = TestErrorRouteImport.update({
path: '/test-error',
getParentRoute: () => rootRouteImport,
} as any)
+const DeviceRoute = DeviceRouteImport.update({
+ id: '/device',
+ path: '/device',
+ getParentRoute: () => rootRouteImport,
+} as any)
const AuthRoute = AuthRouteImport.update({
id: '/auth',
path: '/auth',
@@ -68,11 +76,21 @@ const IndexRoute = IndexRouteImport.update({
path: '/',
getParentRoute: () => rootRouteImport,
} as any)
+const DeviceIndexRoute = DeviceIndexRouteImport.update({
+ id: '/',
+ path: '/',
+ getParentRoute: () => DeviceRoute,
+} as any)
const PublicProjectProjectIdRoute = PublicProjectProjectIdRouteImport.update({
id: '/public-project/$projectId',
path: '/public-project/$projectId',
getParentRoute: () => rootRouteImport,
} as any)
+const DeviceApproveRoute = DeviceApproveRouteImport.update({
+ id: '/approve',
+ path: '/approve',
+ getParentRoute: () => DeviceRoute,
+} as any)
const AuthVerifyOtpRoute = AuthVerifyOtpRouteImport.update({
id: '/verify-otp',
path: '/verify-otp',
@@ -298,12 +316,15 @@ const LayoutAuthenticatedDashboardWorkspaceWorkspaceIdProjectProjectIdTaskTaskId
export interface FileRoutesByFullPath {
'/': typeof IndexRoute
'/auth': typeof AuthRouteWithChildren
+ '/device': typeof DeviceRouteWithChildren
'/test-error': typeof TestErrorRoute
'/auth/check-email': typeof AuthCheckEmailRoute
'/auth/sign-in': typeof AuthSignInRoute
'/auth/sign-up': typeof AuthSignUpRoute
'/auth/verify-otp': typeof AuthVerifyOtpRoute
+ '/device/approve': typeof DeviceApproveRoute
'/public-project/$projectId': typeof PublicProjectProjectIdRoute
+ '/device/': typeof DeviceIndexRoute
'/dashboard': typeof LayoutAuthenticatedDashboardRouteWithChildren
'/invitations': typeof LayoutAuthenticatedInvitationsRoute
'/onboarding': typeof LayoutAuthenticatedOnboardingRoute
@@ -342,7 +363,9 @@ export interface FileRoutesByTo {
'/auth/sign-in': typeof AuthSignInRoute
'/auth/sign-up': typeof AuthSignUpRoute
'/auth/verify-otp': typeof AuthVerifyOtpRoute
+ '/device/approve': typeof DeviceApproveRoute
'/public-project/$projectId': typeof PublicProjectProjectIdRoute
+ '/device': typeof DeviceIndexRoute
'/invitations': typeof LayoutAuthenticatedInvitationsRoute
'/onboarding': typeof LayoutAuthenticatedOnboardingRoute
'/profile-setup': typeof LayoutAuthenticatedProfileSetupRoute
@@ -376,13 +399,16 @@ export interface FileRoutesById {
'/': typeof IndexRoute
'/_layout': typeof LayoutRouteWithChildren
'/auth': typeof AuthRouteWithChildren
+ '/device': typeof DeviceRouteWithChildren
'/test-error': typeof TestErrorRoute
'/_layout/_authenticated': typeof LayoutAuthenticatedRouteWithChildren
'/auth/check-email': typeof AuthCheckEmailRoute
'/auth/sign-in': typeof AuthSignInRoute
'/auth/sign-up': typeof AuthSignUpRoute
'/auth/verify-otp': typeof AuthVerifyOtpRoute
+ '/device/approve': typeof DeviceApproveRoute
'/public-project/$projectId': typeof PublicProjectProjectIdRoute
+ '/device/': typeof DeviceIndexRoute
'/_layout/_authenticated/dashboard': typeof LayoutAuthenticatedDashboardRouteWithChildren
'/_layout/_authenticated/invitations': typeof LayoutAuthenticatedInvitationsRoute
'/_layout/_authenticated/onboarding': typeof LayoutAuthenticatedOnboardingRoute
@@ -418,12 +444,15 @@ export interface FileRouteTypes {
fullPaths:
| '/'
| '/auth'
+ | '/device'
| '/test-error'
| '/auth/check-email'
| '/auth/sign-in'
| '/auth/sign-up'
| '/auth/verify-otp'
+ | '/device/approve'
| '/public-project/$projectId'
+ | '/device/'
| '/dashboard'
| '/invitations'
| '/onboarding'
@@ -462,7 +491,9 @@ export interface FileRouteTypes {
| '/auth/sign-in'
| '/auth/sign-up'
| '/auth/verify-otp'
+ | '/device/approve'
| '/public-project/$projectId'
+ | '/device'
| '/invitations'
| '/onboarding'
| '/profile-setup'
@@ -495,13 +526,16 @@ export interface FileRouteTypes {
| '/'
| '/_layout'
| '/auth'
+ | '/device'
| '/test-error'
| '/_layout/_authenticated'
| '/auth/check-email'
| '/auth/sign-in'
| '/auth/sign-up'
| '/auth/verify-otp'
+ | '/device/approve'
| '/public-project/$projectId'
+ | '/device/'
| '/_layout/_authenticated/dashboard'
| '/_layout/_authenticated/invitations'
| '/_layout/_authenticated/onboarding'
@@ -537,6 +571,7 @@ export interface RootRouteChildren {
IndexRoute: typeof IndexRoute
LayoutRoute: typeof LayoutRouteWithChildren
AuthRoute: typeof AuthRouteWithChildren
+ DeviceRoute: typeof DeviceRouteWithChildren
TestErrorRoute: typeof TestErrorRoute
PublicProjectProjectIdRoute: typeof PublicProjectProjectIdRoute
InvitationAcceptInviteIdRoute: typeof InvitationAcceptInviteIdRoute
@@ -551,6 +586,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof TestErrorRouteImport
parentRoute: typeof rootRouteImport
}
+ '/device': {
+ id: '/device'
+ path: '/device'
+ fullPath: '/device'
+ preLoaderRoute: typeof DeviceRouteImport
+ parentRoute: typeof rootRouteImport
+ }
'/auth': {
id: '/auth'
path: '/auth'
@@ -572,6 +614,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof IndexRouteImport
parentRoute: typeof rootRouteImport
}
+ '/device/': {
+ id: '/device/'
+ path: '/'
+ fullPath: '/device/'
+ preLoaderRoute: typeof DeviceIndexRouteImport
+ parentRoute: typeof DeviceRoute
+ }
'/public-project/$projectId': {
id: '/public-project/$projectId'
path: '/public-project/$projectId'
@@ -579,6 +628,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof PublicProjectProjectIdRouteImport
parentRoute: typeof rootRouteImport
}
+ '/device/approve': {
+ id: '/device/approve'
+ path: '/approve'
+ fullPath: '/device/approve'
+ preLoaderRoute: typeof DeviceApproveRouteImport
+ parentRoute: typeof DeviceRoute
+ }
'/auth/verify-otp': {
id: '/auth/verify-otp'
path: '/verify-otp'
@@ -1009,10 +1065,24 @@ const AuthRouteChildren: AuthRouteChildren = {
const AuthRouteWithChildren = AuthRoute._addFileChildren(AuthRouteChildren)
+interface DeviceRouteChildren {
+ DeviceApproveRoute: typeof DeviceApproveRoute
+ DeviceIndexRoute: typeof DeviceIndexRoute
+}
+
+const DeviceRouteChildren: DeviceRouteChildren = {
+ DeviceApproveRoute: DeviceApproveRoute,
+ DeviceIndexRoute: DeviceIndexRoute,
+}
+
+const DeviceRouteWithChildren =
+ DeviceRoute._addFileChildren(DeviceRouteChildren)
+
const rootRouteChildren: RootRouteChildren = {
IndexRoute: IndexRoute,
LayoutRoute: LayoutRouteWithChildren,
AuthRoute: AuthRouteWithChildren,
+ DeviceRoute: DeviceRouteWithChildren,
TestErrorRoute: TestErrorRoute,
PublicProjectProjectIdRoute: PublicProjectProjectIdRoute,
InvitationAcceptInviteIdRoute: InvitationAcceptInviteIdRoute,
diff --git a/apps/web/src/routes/auth/sign-in.tsx b/apps/web/src/routes/auth/sign-in.tsx
index 96dee8c24..b47c2fe89 100644
--- a/apps/web/src/routes/auth/sign-in.tsx
+++ b/apps/web/src/routes/auth/sign-in.tsx
@@ -23,6 +23,7 @@ import { AuthToggle } from "../../components/auth/toggle";
const signInSearchSchema = z.object({
invitationId: z.string().optional(),
email: z.string().optional(),
+ redirect: z.string().optional(),
});
export const Route = createFileRoute("/auth/sign-in")({
@@ -45,8 +46,20 @@ function SignIn() {
const invitationId = search.invitationId;
const defaultEmail = search.email;
+ const getSafeRedirectPath = () => {
+ const redirectPath = search.redirect;
+ if (redirectPath?.startsWith("/") && !redirectPath.includes("//")) {
+ return redirectPath;
+ }
+ return undefined;
+ };
+
const getCallbackUrl = () => {
const baseUrl = import.meta.env.VITE_CLIENT_URL;
+ const redirectPath = getSafeRedirectPath();
+ if (redirectPath) {
+ return `${baseUrl}${redirectPath}`;
+ }
if (invitationId) {
return `${baseUrl}/invitation/accept/${invitationId}`;
}
@@ -152,7 +165,10 @@ function SignIn() {
};
const handleSignInSuccess = () => {
- if (invitationId) {
+ const redirectPath = getSafeRedirectPath();
+ if (redirectPath) {
+ navigate({ to: redirectPath });
+ } else if (invitationId) {
navigate({ to: `/invitation/accept/${invitationId}` });
} else {
navigate({ to: "/dashboard" });
@@ -346,6 +362,7 @@ function SignIn() {
<OtpSignInForm
invitationId={invitationId}
defaultEmail={defaultEmail}
+ redirect={getSafeRedirectPath()}
onSuccess={handleSignInSuccess}
/>
) : (
diff --git a/apps/web/src/routes/auth/verify-otp.tsx b/apps/web/src/routes/auth/verify-otp.tsx
index cbe3451fc..67836b374 100644
--- a/apps/web/src/routes/auth/verify-otp.tsx
+++ b/apps/web/src/routes/auth/verify-otp.tsx
@@ -31,13 +31,16 @@ export const Route = createFileRoute("/auth/verify-otp")({
validateSearch: (search: Record<string, unknown>) => ({
email: search.email as string,
invitationId: search.invitationId as string | undefined,
+ redirect: search.redirect as string | undefined,
}),
});
function VerifyOtp() {
const { t } = useTranslation();
const { history } = useRouter();
- const { email, invitationId } = useSearch({ from: "/auth/verify-otp" });
+ const { email, invitationId, redirect } = useSearch({
+ from: "/auth/verify-otp",
+ });
const [isPending, setIsPending] = useState(false);
const verifyOtpSchema = useMemo(
@@ -55,6 +58,13 @@ function VerifyOtp() {
defaultValues: { otp: "" },
});
+ const safeRedirect = useMemo(() => {
+ if (redirect?.startsWith("/") && !redirect.includes("//")) {
+ return redirect;
+ }
+ return undefined;
+ }, [redirect]);
+
const onSubmit = useCallback(
async (data: VerifyOtpFormValues) => {
setIsPending(true);
@@ -72,7 +82,9 @@ function VerifyOtp() {
}
toast.success(t("auth:verifyOtp.toast.signedInSuccess"));
- if (invitationId) {
+ if (safeRedirect) {
+ history.push(safeRedirect);
+ } else if (invitationId) {
history.push(`/invitation/accept/${invitationId}`);
} else {
history.push("/dashboard");
@@ -87,7 +99,7 @@ function VerifyOtp() {
setIsPending(false);
}
},
- [email, invitationId, history, t],
+ [email, invitationId, history, safeRedirect, t],
);
useEffect(() => {
diff --git a/apps/web/src/routes/device.tsx b/apps/web/src/routes/device.tsx
new file mode 100644
index 000000000..a638a4f10
--- /dev/null
+++ b/apps/web/src/routes/device.tsx
@@ -0,0 +1,9 @@
+import { createFileRoute, Outlet } from "@tanstack/react-router";
+
+export const Route = createFileRoute("/device")({
+ component: DeviceLayout,
+});
+
+function DeviceLayout() {
+ return <Outlet />;
+}
diff --git a/apps/web/src/routes/device/approve.tsx b/apps/web/src/routes/device/approve.tsx
new file mode 100644
index 000000000..ca9f095bc
--- /dev/null
+++ b/apps/web/src/routes/device/approve.tsx
@@ -0,0 +1,160 @@
+import {
+ createFileRoute,
+ useNavigate,
+ useSearch,
+} from "@tanstack/react-router";
+import { useState } from "react";
+import { z } from "zod/v4";
+import { AuthLayout } from "@/components/auth/layout";
+import { Button } from "@/components/ui/button";
+import { authClient } from "@/lib/auth-client";
+import { toast } from "@/lib/toast";
+
+const approveSearchSchema = z.object({
+ user_code: z.string().optional(),
+});
+
+export const Route = createFileRoute("/device/approve")({
+ component: DeviceApprovePage,
+ validateSearch: approveSearchSchema,
+});
+
+function DeviceApprovePage() {
+ const navigate = useNavigate();
+ const search = useSearch({ from: "/device/approve" });
+ const { data: session, isPending } = authClient.useSession();
+ const [processing, setProcessing] = useState(false);
+
+ const normalizedCode =
+ search.user_code?.trim().replace(/-/g, "").toUpperCase() ?? "";
+
+ if (isPending) {
+ return (
+ <AuthLayout title="Approve device" subtitle="Loading…">
+ <div className="text-sm text-muted-foreground">Checking session…</div>
+ </AuthLayout>
+ );
+ }
+
+ if (!session?.user) {
+ if (!normalizedCode) {
+ return (
+ <AuthLayout
+ title="Approve device"
+ subtitle="No device code was provided."
+ >
+ <Button
+ className="w-full"
+ variant="secondary"
+ onClick={() => void navigate({ to: "/device" })}
+ >
+ Enter a code
+ </Button>
+ </AuthLayout>
+ );
+ }
+ const redirectTarget = `/device/approve?user_code=${encodeURIComponent(normalizedCode)}`;
+ return (
+ <AuthLayout
+ title="Sign in to continue"
+ subtitle="Sign in to approve or deny this device request."
+ >
+ <Button
+ className="w-full"
+ onClick={() =>
+ void navigate({
+ to: "/auth/sign-in",
+ search: { redirect: redirectTarget },
+ })
+ }
+ >
+ Sign in
+ </Button>
+ </AuthLayout>
+ );
+ }
+
+ if (!normalizedCode) {
+ return (
+ <AuthLayout
+ title="Approve device"
+ subtitle="No device code was provided."
+ >
+ <Button
+ className="w-full"
+ variant="secondary"
+ onClick={() => void navigate({ to: "/device" })}
+ >
+ Enter a code
+ </Button>
+ </AuthLayout>
+ );
+ }
+
+ const handleApprove = async () => {
+ setProcessing(true);
+ try {
+ const res = await authClient.device.approve({
+ userCode: normalizedCode,
+ });
+ if (res.error) {
+ toast.error(res.error.error_description ?? "Could not approve");
+ return;
+ }
+ toast.success("Device connected");
+ void navigate({ to: "/dashboard" });
+ } catch {
+ toast.error("Could not approve");
+ } finally {
+ setProcessing(false);
+ }
+ };
+
+ const handleDeny = async () => {
+ setProcessing(true);
+ try {
+ const res = await authClient.device.deny({
+ userCode: normalizedCode,
+ });
+ if (res.error) {
+ toast.error(res.error.error_description ?? "Could not deny");
+ return;
+ }
+ toast.message("Request cancelled");
+ void navigate({ to: "/dashboard" });
+ } catch {
+ toast.error("Could not deny");
+ } finally {
+ setProcessing(false);
+ }
+ };
+
+ return (
+ <AuthLayout
+ title="Approve device"
+ subtitle="A device is requesting access to your Kaneo account."
+ >
+ <div className="space-y-4">
+ <p className="text-center font-mono text-sm tracking-wide">
+ {normalizedCode}
+ </p>
+ <div className="flex gap-2">
+ <Button
+ className="flex-1"
+ disabled={processing}
+ onClick={() => void handleApprove()}
+ >
+ Approve
+ </Button>
+ <Button
+ variant="outline"
+ disabled={processing}
+ onClick={() => void handleDeny()}
+ >
+ Deny
+ </Button>
+ </div>
+ </div>
+ </AuthLayout>
+ );
+}
diff --git a/apps/web/src/routes/device/index.tsx b/apps/web/src/routes/device/index.tsx
new file mode 100644
index 000000000..9f5851c65
--- /dev/null
+++ b/apps/web/src/routes/device/index.tsx
@@ -0,0 +1,79 @@
+import {
+ createFileRoute,
+ useNavigate,
+ useSearch,
+} from "@tanstack/react-router";
+import { useState } from "react";
+import { z } from "zod/v4";
+import { AuthLayout } from "@/components/auth/layout";
+import { Button } from "@/components/ui/button";
+import { Input } from "@/components/ui/input";
+import { authClient } from "@/lib/auth-client";
+import { toast } from "@/lib/toast";
+
+const deviceSearchSchema = z.object({
+ user_code: z.string().optional(),
+});
+
+export const Route = createFileRoute("/device/")({
+ component: DevicePage,
+ validateSearch: deviceSearchSchema,
+});
+
+function DevicePage() {
+ const navigate = useNavigate();
+ const search = useSearch({ from: "/device/" });
+ const [code, setCode] = useState(search.user_code ?? "");
+ const [loading, setLoading] = useState(false);
+
+ const handleSubmit = async (e: React.FormEvent) => {
+ e.preventDefault();
+ const formatted = code.trim().replace(/-/g, "").toUpperCase();
+ if (formatted.length < 4) {
+ toast.error("Enter the code shown on your device.");
+ return;
+ }
+ setLoading(true);
+ try {
+ const res = await authClient.device({
+ query: { user_code: formatted },
+ });
+ if (res.error) {
+ toast.error(
+ "error_description" in res.error
+ ? String(res.error.error_description)
+ : "Invalid or expired code",
+ );
+ return;
+ }
+ void navigate({
+ to: "/device/approve",
+ search: { user_code: formatted },
+ });
+ } catch {
+ toast.error("Invalid or expired code");
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ return (
+ <AuthLayout
+ title="Connect a device"
+ subtitle="Enter the code from your CLI or app to continue."
+ >
+ <form onSubmit={handleSubmit} className="space-y-4">
+ <Input
+ value={code}
+ onChange={(e) => setCode(e.target.value)}
+ placeholder="e.g. ABCD-1234"
+ autoCapitalize="characters"
+ autoComplete="one-time-code"
+ />
+ <Button type="submit" className="w-full" disabled={loading}>
+ Continue
+ </Button>
+ </form>
+ </AuthLayout>
+ );
+}
diff --git a/tests/api-integration/device-authorization.test.ts b/tests/api-integration/device-authorization.test.ts
new file mode 100644
index 000000000..666cc4538
--- /dev/null
+++ b/tests/api-integration/device-authorization.test.ts
@@ -0,0 +1,338 @@
+import { createHash, randomUUID } from "node:crypto";
+import { eq } from "drizzle-orm";
+import { beforeEach, describe, expect, it } from "vitest";
+import db, { schema } from "../../apps/api/src/database";
+import { createApp } from "../../apps/api/src/index";
+import { resetTestDatabase } from "./helpers/database";
+import { createWorkspaceMember } from "./helpers/fixtures";
+
+const origin = "http://localhost:5173";
+
+function mergeCookieJar(cookieJar: string, res: Response): string {
+ const incoming = res.headers.getSetCookie?.() ?? [];
+ if (incoming.length === 0) {
+ return cookieJar;
+ }
+ const pairs = incoming.map((c) => c.split(";")[0]).filter(Boolean);
+ const prefix = cookieJar ? `${cookieJar}; ` : "";
+ return `${prefix}${pairs.join("; ")}`;
+}
+
+async function hashApiKeyForTest(key: string): Promise<string> {
+ const hash = createHash("sha256").update(key).digest();
+ return hash
+ .toString("base64")
+ .replace(/\+/g, "-")
+ .replace(/\//g, "_")
+ .replace(/=/g, "");
+}
+
+async function signUpAndGetCookie(
+ app: ReturnType<typeof createApp>["app"],
+ email: string,
+ password: string,
+): Promise<string> {
+ let jar = "csrf=1";
+ const signUp = await app.request("/api/auth/sign-up/email", {
+ method: "POST",
+ headers: {
+ "content-type": "application/json",
+ Origin: origin,
+ Cookie: jar,
+ },
+ body: JSON.stringify({
+ name: "Device flow user",
+ email,
+ password,
+ }),
+ });
+
+ expect(signUp.status).toBe(200);
+ jar = mergeCookieJar(jar, signUp);
+
+ const signIn = await app.request("/api/auth/sign-in/email", {
+ method: "POST",
+ headers: {
+ "content-type": "application/json",
+ Origin: origin,
+ Cookie: jar,
+ },
+ body: JSON.stringify({ email, password }),
+ });
+
+ expect(signIn.status).toBe(200);
+ jar = mergeCookieJar(jar, signIn);
+ return jar;
+}
+
+describe("API integration: device authorization (RFC 8628)", () => {
+ beforeEach(async () => {
+ await resetTestDatabase();
+ });
+
+ it("returns device and user codes for an allowed client_id", async () => {
+ const { app } = createApp();
+
+ const res = await app.request("/api/auth/device/code", {
+ method: "POST",
+ headers: {
+ "content-type": "application/json",
+ Origin: origin,
+ },
+ body: JSON.stringify({ client_id: "kaneo-cli" }),
+ });
+
+ expect(res.status).toBe(200);
+ const body = (await res.json()) as Record<string, unknown>;
+ expect(body.device_code).toEqual(expect.any(String));
+ expect(body.user_code).toEqual(expect.any(String));
+ expect(body.verification_uri).toEqual(expect.any(String));
+ expect(body.interval).toEqual(expect.any(Number));
+ expect(body.expires_in).toEqual(expect.any(Number));
+ });
+
+ it("rejects disallowed client_id", async () => {
+ const { app } = createApp();
+
+ const res = await app.request("/api/auth/device/code", {
+ method: "POST",
+ headers: {
+ "content-type": "application/json",
+ Origin: origin,
+ },
+ body: JSON.stringify({ client_id: "unknown-client" }),
+ });
+
+ expect(res.status).toBe(400);
+ const body = (await res.json()) as { error?: string };
+ expect(body.error).toBe("invalid_client");
+ });
+
+ it("returns authorization_pending before approval", async () => {
+ const { app } = createApp();
+
+ const codeRes = await app.request("/api/auth/device/code", {
+ method: "POST",
+ headers: {
+ "content-type": "application/json",
+ Origin: origin,
+ },
+ body: JSON.stringify({ client_id: "kaneo-cli" }),
+ });
+ const { device_code } = (await codeRes.json()) as { device_code: string };
+
+ const tokenRes = await app.request("/api/auth/device/token", {
+ method: "POST",
+ headers: {
+ "content-type": "application/json",
+ Origin: origin,
+ },
+ body: JSON.stringify({
+ grant_type: "urn:ietf:params:oauth:grant-type:device_code",
+ device_code,
+ client_id: "kaneo-cli",
+ }),
+ });
+
+ expect(tokenRes.status).toBe(400);
+ const body = (await tokenRes.json()) as { error: string };
+ expect(body.error).toBe("authorization_pending");
+ });
+
+ it("issues an access token after approval and allows API access with Bearer", async () => {
+ const email = `device-${randomUUID()}@example.com`;
+ const password = "device-flow-password-12345";
+
+ const { app } = createApp();
+ const cookieJar = await signUpAndGetCookie(app, email, password);
+
+ const sessionRes = await app.request("/api/auth/get-session", {
+ headers: {
+ Cookie: cookieJar,
+ Origin: origin,
+ },
+ });
+ expect(sessionRes.status).toBe(200);
+ const sessionJson = (await sessionRes.json()) as {
+ user?: { id: string };
+ };
+ const userId = sessionJson.user?.id;
+ if (!userId) {
+ throw new Error("expected session user id after sign-in");
+ }
+
+ const workspaceId = `ws-${randomUUID()}`;
+ await db.insert(schema.workspaceTable).values({
+ id: workspaceId,
+ name: "Device test workspace",
+ slug: `slug-${randomUUID()}`,
+ createdAt: new Date(),
+ });
+ await db.insert(schema.workspaceUserTable).values({
+ workspaceId,
+ userId,
+ role: "owner",
+ joinedAt: new Date(),
+ });
+
+ const codeRes = await app.request("/api/auth/device/code", {
+ method: "POST",
+ headers: {
+ "content-type": "application/json",
+ Origin: origin,
+ },
+ body: JSON.stringify({ client_id: "kaneo-cli" }),
+ });
+ expect(codeRes.status).toBe(200);
+ const devicePayload = (await codeRes.json()) as {
+ device_code: string;
+ user_code: string;
+ interval: number;
+ };
+
+ const approveRes = await app.request("/api/auth/device/approve", {
+ method: "POST",
+ headers: {
+ "content-type": "application/json",
+ Origin: origin,
+ Cookie: cookieJar,
+ },
+ body: JSON.stringify({
+ userCode: devicePayload.user_code,
+ }),
+ });
+ expect(approveRes.status).toBe(200);
+
+ let accessToken: string | undefined;
+ const maxAttempts = 40;
+ for (let i = 0; i < maxAttempts; i++) {
+ if (i > 0) {
+ await new Promise((r) =>
+ setTimeout(r, devicePayload.interval * 1000 + 50),
+ );
+ }
+ const tokenRes = await app.request("/api/auth/device/token", {
+ method: "POST",
+ headers: {
+ "content-type": "application/json",
+ Origin: origin,
+ },
+ body: JSON.stringify({
+ grant_type: "urn:ietf:params:oauth:grant-type:device_code",
+ device_code: devicePayload.device_code,
+ client_id: "kaneo-cli",
+ }),
+ });
+ if (tokenRes.status === 200) {
+ const t = (await tokenRes.json()) as { access_token?: string };
+ accessToken = t.access_token;
+ break;
+ }
+ const err = (await tokenRes.json()) as { error: string };
+ if (err.error !== "authorization_pending" && err.error !== "slow_down") {
+ throw new Error(`Unexpected token error: ${err.error}`);
+ }
+ }
+
+ expect(accessToken).toBeTruthy();
+
+ const projectsRes = await app.request(
+ `/api/project?workspaceId=${encodeURIComponent(workspaceId)}`,
+ {
+ headers: {
+ Authorization: `Bearer ${accessToken}`,
+ },
+ },
+ );
+ expect(projectsRes.status).toBe(200);
+ const projects = (await projectsRes.json()) as unknown[];
+ expect(Array.isArray(projects)).toBe(true);
+ });
+
+ it("still authenticates with a valid API key Bearer", async () => {
+ const member = await createWorkspaceMember();
+
+ const rawKey = `kaneo_test_${randomUUID()}`;
+ const hashed = await hashApiKeyForTest(rawKey);
+ const now = new Date();
+
+ await db.insert(schema.apikeyTable).values({
+ referenceId: member.user.id,
+ userId: member.user.id,
+ key: hashed,
+ name: "integration device test",
+ start: rawKey.slice(0, 12),
+ prefix: "kaneo",
+ createdAt: now,
+ updatedAt: now,
+ });
+
+ const { app } = createApp();
+
+ const res = await app.request(
+ `/api/project?workspaceId=${encodeURIComponent(member.workspace.id)}`,
+ {
+ headers: {
+ Authorization: `Bearer ${rawKey}`,
+ },
+ },
+ );
+
+ expect(res.status).toBe(200);
+ const rows = await db
+ .select()
+ .from(schema.apikeyTable)
+ .where(eq(schema.apikeyTable.key, hashed));
+ expect(rows.length).toBe(1);
+ });
+
+ it("rejects an invalid Bearer token even when a valid session cookie is present", async () => {
+ const email = `device-bearer-${randomUUID()}@example.com`;
+ const password = "device-flow-password-12345";
+
+ const { app } = createApp();
+ const cookieJar = await signUpAndGetCookie(app, email, password);
+
+ const sessionRes = await app.request("/api/auth/get-session", {
+ headers: {
+ Cookie: cookieJar,
+ Origin: origin,
+ },
+ });
+ expect(sessionRes.status).toBe(200);
+ const sessionJson = (await sessionRes.json()) as {
+ user?: { id: string };
+ };
+ const userId = sessionJson.user?.id;
+ if (!userId) {
+ throw new Error("expected session user id after sign-in");
+ }
+
+ const workspaceId = `ws-${randomUUID()}`;
+ await db.insert(schema.workspaceTable).values({
+ id: workspaceId,
+ name: "Bearer fallback workspace",
+ slug: `slug-${randomUUID()}`,
+ createdAt: new Date(),
+ });
+ await db.insert(schema.workspaceUserTable).values({
+ workspaceId,
+ userId,
+ role: "owner",
+ joinedAt: new Date(),
+ });
+
+ const res = await app.request(
+ `/api/project?workspaceId=${encodeURIComponent(workspaceId)}`,
+ {
+ headers: {
+ Authorization: "Bearer definitely-not-a-real-token",
+ Cookie: cookieJar,
+ Origin: origin,
+ },
+ },
+ );
+
+ expect(res.status).toBe(401);
+ });
+});
diff --git a/tests/api-integration/setup.ts b/tests/api-integration/setup.ts
index 2a6c32c2c..db8273b2c 100644
--- a/tests/api-integration/setup.ts
+++ b/tests/api-integration/setup.ts
@@ -86,6 +86,7 @@ process.env.CUSTOM_OAUTH_USER_INFO_URL = "";
process.env.CUSTOM_OAUTH_SCOPES = "";
process.env.CUSTOM_OAUTH_RESPONSE_TYPE = "";
process.env.CUSTOM_OAUTH_DISCOVERY_URL = "";
+process.env.DEVICE_AUTH_CLIENT_IDS = "kaneo-cli";
afterEach(() => {
vi.restoreAllMocks();