Skip to content

Commit

Permalink
Merge pull request #4 from chedakr/feature/login-jwt
Browse files Browse the repository at this point in the history
feat: jwt 인증 방식으로 변경
  • Loading branch information
Xvezda authored May 13, 2024
2 parents bc93c6d + b0123ae commit 62dded0
Show file tree
Hide file tree
Showing 21 changed files with 801 additions and 334 deletions.
12 changes: 12 additions & 0 deletions apps/api/drizzle/0000_marvelous_christian_walker.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE TABLE `users` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`user_id` text NOT NULL,
`user_name` text NOT NULL,
`user_image` text,
`user_type` text NOT NULL,
`created_at` integer NOT NULL,
`updated_at` integer NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `idx_users_user_id` ON `users` (`user_id`);--> statement-breakpoint
CREATE INDEX `idx_users_user_name` ON `users` (`user_name`);
17 changes: 0 additions & 17 deletions apps/api/drizzle/0000_stale_doorman.sql

This file was deleted.

51 changes: 8 additions & 43 deletions apps/api/drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "5",
"dialect": "sqlite",
"id": "adb7d579-e149-4d0e-9c32-f5c0f77d5f8a",
"id": "21a996cf-3dbe-41e4-b796-aeae28f4e6fd",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"users": {
Expand Down Expand Up @@ -35,6 +35,13 @@
"notNull": false,
"autoincrement": false
},
"user_type": {
"name": "user_type",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
Expand All @@ -48,34 +55,6 @@
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"access_token": {
"name": "access_token",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"refresh_token": {
"name": "refresh_token",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"token_type": {
"name": "token_type",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"expire_at": {
"name": "expire_at",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {
Expand All @@ -92,20 +71,6 @@
"user_name"
],
"isUnique": false
},
"idx_users_created_at": {
"name": "idx_users_created_at",
"columns": [
"created_at"
],
"isUnique": false
},
"idx_users_updated_at": {
"name": "idx_users_updated_at",
"columns": [
"updated_at"
],
"isUnique": false
}
},
"foreignKeys": {},
Expand Down
4 changes: 2 additions & 2 deletions apps/api/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"idx": 0,
"version": "5",
"when": 1713153522431,
"tag": "0000_stale_doorman",
"when": 1715078125961,
"tag": "0000_marvelous_christian_walker",
"breakpoints": true
}
]
Expand Down
5 changes: 3 additions & 2 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"@libsql/client": "^0.6.0",
"drizzle-orm": "^0.30.8",
"hono": "^4.2.4"
"hono": "^4.2.4",
"jose": "^5.2.4"
}
}
}
7 changes: 1 addition & 6 deletions apps/api/src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@ export const users = sqliteTable('users', {
userId: text('user_id').notNull(),
userName: text('user_name').notNull(),
userImage: text('user_image'),
userType: text('user_type').notNull(),
createdAt: integer('created_at', { mode: 'timestamp_ms' }).notNull(),
updatedAt: integer('updated_at', { mode: 'timestamp_ms' }).notNull(),
accessToken: text('access_token'),
refreshToken: text('refresh_token'),
tokenType: text('token_type'),
expireAt: integer('expire_at', { mode: 'timestamp_ms' }),
}, (table) => {
return {
idxUserId: uniqueIndex('idx_users_user_id').on(table.userId),
idxUserName: index('idx_users_user_name').on(table.userName),
idxCreatedAt: index('idx_users_created_at').on(table.createdAt),
idxUpdatedAt: index('idx_users_updated_at').on(table.updatedAt),
};
});
23 changes: 22 additions & 1 deletion apps/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { HTTPException } from 'hono/http-exception';
import auth from './services/auth/v1/route';
import { Env } from '@/typings';

const app = new Hono<{ Bindings: Env }>();

app.onError((err, c) => {
console.error(`${err}`);

if (err instanceof HTTPException) {
return c.json({ message: err.message }, err.status);
}
return c.json({ message: 'Internal Server Error' }, 500);
});

app.use('*', cors({
credentials: true,
origin: (origin, c) => {
if (c.env.DEV) {
return origin;
}

try {
const originUrl = new URL(origin);
if (originUrl.hostname === 'cheda.kr' || originUrl.hostname.endsWith('.cheda.kr')) {
Expand All @@ -28,4 +38,15 @@ app.get('/', async (c) => {

app.route('/services/auth/v1', auth);

app.use('/services/buffer/v1/*', async (c, next) => {
if (c.env.DEV) {
const reqUrl = new URL(c.req.url);
reqUrl.host = 'localhost:8788';

const response = await fetch(reqUrl, c.req.raw.clone());
c.res = new Response(response.body, response);
}
await next();
});

export default app;
Loading

0 comments on commit 62dded0

Please sign in to comment.