Skip to content

Commit

Permalink
fix forges tokens refreshing
Browse files Browse the repository at this point in the history
  • Loading branch information
anbraten committed Aug 15, 2023
1 parent 30d6d18 commit 3bc5d1e
Show file tree
Hide file tree
Showing 21 changed files with 156 additions and 856 deletions.
1 change: 1 addition & 0 deletions composables/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const useAuth = () => {
}

// TODO: load user data
// TODO: fix for SSR
(async () => {
user.value = await $fetch('/api/user');
})();
Expand Down
2 changes: 1 addition & 1 deletion drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Config } from 'drizzle-kit';
// For config references visit https://orm.drizzle.team/kit-docs/config-reference

export default {
schema: ['./server/schemas/schemas.ts'],
schema: ['./server/schemas/*schemas.ts'],
out: './server/db/migrations',
dbCredentials: {
url: 'code_captain.db',
Expand Down
2 changes: 2 additions & 0 deletions server/api/auth/callback.get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default defineEventHandler(async (event) => {
forgeId: forgeModel.id,
remoteUserId: oauthUser.remoteUserId,
accessToken: tokens.accessToken,
accessTokenExpiresIn: tokens.accessTokenExpiresIn,
refreshToken: tokens.refreshToken,
})
.onConflictDoNothing()
Expand Down Expand Up @@ -101,6 +102,7 @@ export default defineEventHandler(async (event) => {
forgeId: forgeModel.id,
remoteUserId: oauthUser.remoteUserId,
accessToken: tokens.accessToken,
accessTokenExpiresIn: tokens.accessTokenExpiresIn,
refreshToken: tokens.refreshToken,
})
.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CREATE TABLE `forges` (
`name` text,
`type` text NOT NULL,
`host` text,
`allowLogin` integer,
`clientId` text NOT NULL,
`clientSecret` text NOT NULL
);
Expand All @@ -11,7 +12,15 @@ CREATE TABLE `userForges` (
`id` integer PRIMARY KEY NOT NULL,
`userId` integer NOT NULL,
`forgeId` integer NOT NULL,
`remoteUserId` text NOT NULL
`remoteUserId` text NOT NULL,
`accessToken` text NOT NULL,
`accessTokenExpiresIn` integer NOT NULL,
`refreshToken` text
);
--> statement-breakpoint
ALTER TABLE `users` DROP COLUMN `login`;
CREATE TABLE `users` (
`id` integer PRIMARY KEY NOT NULL,
`name` text,
`avatarUrl` text,
`email` text
);
7 changes: 0 additions & 7 deletions server/db/migrations/0000_moaning_wendell_vaughn.sql

This file was deleted.

1 change: 0 additions & 1 deletion server/db/migrations/0002_modern_polaris.sql

This file was deleted.

3 changes: 0 additions & 3 deletions server/db/migrations/0003_worried_aqueduct.sql

This file was deleted.

1 change: 0 additions & 1 deletion server/db/migrations/0004_sweet_mandroid.sql

This file was deleted.

2 changes: 0 additions & 2 deletions server/db/migrations/0005_tricky_jack_flag.sql

This file was deleted.

119 changes: 114 additions & 5 deletions server/db/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"version": "5",
"dialect": "sqlite",
"id": "26bc539a-d250-40d4-a924-90bd3ebe405a",
"id": "7e38af1c-fd4f-461b-8856-db3d20cd480c",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"users": {
"name": "users",
"forges": {
"name": "forges",
"columns": {
"id": {
"name": "id",
Expand All @@ -14,13 +14,122 @@
"notNull": true,
"autoincrement": false
},
"login": {
"name": "login",
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"type": {
"name": "type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"host": {
"name": "host",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"allowLogin": {
"name": "allowLogin",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"clientId": {
"name": "clientId",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"clientSecret": {
"name": "clientSecret",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"userForges": {
"name": "userForges",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"userId": {
"name": "userId",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"forgeId": {
"name": "forgeId",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"remoteUserId": {
"name": "remoteUserId",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"accessToken": {
"name": "accessToken",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"accessTokenExpiresIn": {
"name": "accessTokenExpiresIn",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"refreshToken": {
"name": "refreshToken",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"users": {
"name": "users",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
Expand Down
139 changes: 0 additions & 139 deletions server/db/migrations/meta/0001_snapshot.json

This file was deleted.

Loading

0 comments on commit 3bc5d1e

Please sign in to comment.