Skip to content

Commit

Permalink
add middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
azhe403 committed Nov 21, 2024
1 parent 9677547 commit 77a0196
Show file tree
Hide file tree
Showing 20 changed files with 236 additions and 1,360 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node-terminal",
"request": "launch",
"name": "Run NPM Script",
"command": "npm run shadcn-console"
}

]
}
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@zizibot/shadcn": "workspace:*",
"next": "14.2.8",
"next": "catalog:",
"react": "catalog:react18",
"react-dom": "catalog:react18"
},
Expand Down
9 changes: 9 additions & 0 deletions apps/shadcn-console/app/pendekin/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import MainLayout from "@zizibot/shadcn/components/main-layout";

const ListPendekin = () => (
<MainLayout>
<h1>pendekin</h1>
</MainLayout>
);

export default ListPendekin
22 changes: 22 additions & 0 deletions apps/shadcn-console/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NextRequest } from "next/server";
import { getUserInfo } from "@zizibot/rest-client/internal/user-rest";

export function middleware(request: NextRequest) {
console.log("middleware", request.url);

getUserInfo().then(r => console.debug('user-info', r));
}

// export const config = {
// matcher: [
// /*
// * Match all request paths except for the ones starting with:
// * - api (API routes)
// * - _next/static (static files)
// * - _next/image (image optimization files)
// * - favicon.ico, sitemap.xml, robots.txt (metadata files)
// */
// '/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)',
// '/:path*',
// ],
// }
3 changes: 3 additions & 0 deletions apps/shadcn-console/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
transpilePackages: ["@zizibot/shadcn"],
env: {
API_BASE_URL: process.env.API_BASE_URL,
},
};

export default nextConfig;
5 changes: 3 additions & 2 deletions apps/shadcn-console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "next dev --port 7130",
"build": "next build",
"start": "next start",
"lint": "eslint . --max-warnings 0"
},
"dependencies": {
"@zizibot/shadcn": "workspace:*",
"next": "14.2.8",
"@zizibot/rest-client": "workspace:*",
"next": "catalog:",
"react": "catalog:react18",
"react-dom": "catalog:react18"
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@repo/typescript-config": "workspace:*",
"husky": "^9.1.7",
"prettier": "catalog:",
"turbo": "2.1.1"
"turbo": "^2.3.1"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
20 changes: 0 additions & 20 deletions packages/logger/tsconfig.json

This file was deleted.

11 changes: 0 additions & 11 deletions packages/logger/tsup.config.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
"devDependencies": {
"@repo/eslint-config": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@types/jest": "^29.5.14",
"@types/jest": "catalog:",
"@types/node": "^22.9.0",
"jest": "catalog:",
"tsup": "^8.3.5",
"typescript": "^5.6.3"
}
}
}
1 change: 1 addition & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucide-react": "catalog:",
"next": "catalog:",
"next-themes": "^0.4.3",
"tailwind-merge": "^2.3.0",
"tailwindcss-animate": "^1.0.7"
Expand Down
25 changes: 18 additions & 7 deletions packages/ui/src/components/app-sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react"
import { GalleryVerticalEnd } from "lucide-react"
import { GalleryVerticalEnd } from "lucide-react";

import {
Sidebar,
Expand All @@ -14,10 +14,21 @@ import {
SidebarMenuSubItem,
SidebarRail,
} from "@zizibot/shadcn/components/ui/sidebar"
import Link from "next/link";

// This is sample data.
const data = {
navMain: [
{
title: "Productivity",
url: "#",
items: [
{
title: "Pendekin",
url: "/pendekin",
}
],
},
{
title: "Getting Started",
url: "#",
Expand Down Expand Up @@ -154,7 +165,7 @@ const data = {
],
},
],
}
};

export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
return (
Expand All @@ -163,15 +174,15 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
<SidebarMenu>
<SidebarMenuItem>
<SidebarMenuButton size="lg" asChild>
<a href="#">
<Link href="/">
<div className="flex aspect-square size-8 items-center justify-center rounded-lg bg-sidebar-primary text-sidebar-primary-foreground">
<GalleryVerticalEnd className="size-4" />
</div>
<div className="flex flex-col gap-0.5 leading-none">
<span className="font-semibold">ZiziBot Console</span>
<span className="">v1.0.0</span>
</div>
</a>
</Link>
</SidebarMenuButton>
</SidebarMenuItem>
</SidebarMenu>
Expand All @@ -182,16 +193,16 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
{data.navMain.map((item) => (
<SidebarMenuItem key={item.title}>
<SidebarMenuButton asChild>
<a href={item.url} className="font-medium">
<Link href={item.url} className="font-medium">
{item.title}
</a>
</Link>
</SidebarMenuButton>
{item.items?.length ? (
<SidebarMenuSub>
{item.items.map((item) => (
<SidebarMenuSubItem key={item.title}>
<SidebarMenuSubButton asChild isActive={item.isActive}>
<a href={item.url}>{item.title}</a>
<Link href={item.url}>{item.title}</Link>
</SidebarMenuSubButton>
</SidebarMenuSubItem>
))}
Expand Down
6 changes: 3 additions & 3 deletions packages/zizibot-rest-client/src/internal/user-rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { TelegramUserLogin, TelegramUserLoginResponse, UserSessionInfo } from '@

export async function validateTelegramSession(data: TelegramUserLogin) {
const response = await apiClient.post<ApiResponse<TelegramUserLoginResponse>>('/api/user/session/telegram', data);

console.debug('auth telegram', response);

return response.data;
Expand All @@ -17,6 +16,7 @@ export async function validateCurrentSession() {

export async function getUserInfo() {
const response = await apiClient.get<ApiResponse<UserSessionInfo>>('/api/user/info');
console.debug(getUserInfo.name, response.status);
console.debug('get user info', response);

return response.data;
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "@zizibot/logger",
"name": "@zizibot/utils",
"version": "1.0.0",
"description": "",
"main": "index.js",
"exports": {
"./logger": "./src/logger.ts"
".": "./src/*.ts"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -13,9 +13,9 @@
"devDependencies": {
"@repo/eslint-config": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@types/jest": "^29.2.5",
"@types/jest": "catalog:",
"@types/node": "^22.9.0",
"jest": "catalog:",
"tsup": "^8.3.5"
}
}
}
File renamed without changes.
15 changes: 15 additions & 0 deletions packages/zizibot-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "@repo/typescript-config/base.json",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@zizibot/utils/*": ["./src/*"]
}
},
"include": [
"src"
],
"exclude": [
"node_modules"
]
}
File renamed without changes.
Loading

0 comments on commit 77a0196

Please sign in to comment.