- Removed the API proxy middleware and integrated RPC routes for user authentication. - Implemented JWT token generation and validation in the authentication middleware. - Enhanced user registration and login processes with password hashing and token management. - Added new routes for user password reset and Google OAuth login. - Introduced health check endpoints for service monitoring. - Updated gRPC client methods for user management, including password updates. - Refactored utility functions for token handling and Redis interactions. - Improved type definitions for better TypeScript support.
43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { authenticate } from "@/server/middlewares/authenticate";
|
|
import {
|
|
exposeTinyRpc,
|
|
httpServerAdapter,
|
|
validateFn,
|
|
} from "@hiogawa/tiny-rpc";
|
|
import { tinyassert } from "@hiogawa/utils";
|
|
import { Hono } from "hono";
|
|
import { getContext } from "hono/context-storage";
|
|
import { jwt } from "hono/jwt";
|
|
import { z } from "zod";
|
|
import { meMethods } from "./me";
|
|
|
|
const routes = {
|
|
// define as a bare function
|
|
checkId: (id: string) => {
|
|
const context = getContext();
|
|
console.log(context.req.raw.headers);
|
|
return id === "good";
|
|
},
|
|
...meMethods
|
|
};
|
|
export type RpcRoutes = typeof routes;
|
|
export const endpoint = "/rpc";
|
|
export const pathsForGET: (keyof typeof routes)[] = ["checkId"];
|
|
|
|
export function registerRpcRoutes(app: Hono) {
|
|
app.use(endpoint, authenticate, async (c, next) => {
|
|
if (c.req.path !== endpoint && !c.req.path.startsWith(endpoint + "/")) {
|
|
return await next();
|
|
}
|
|
const handler = exposeTinyRpc({
|
|
routes,
|
|
adapter: httpServerAdapter({ endpoint }),
|
|
});
|
|
const res = await handler({ request: c.req.raw });
|
|
if (res) {
|
|
return res;
|
|
}
|
|
return await next();
|
|
});
|
|
}
|