2begyb commited on
Commit
b4c6359
·
verified ·
1 Parent(s): 9af664d

Temporary bypass: Disable login and session check for direct access

Browse files
Files changed (3) hide show
  1. Home.tsx +153 -0
  2. trpc.ts +59 -0
  3. useAuth.ts +86 -0
Home.tsx ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { useAuth } from "@/_core/hooks/useAuth";
2
+ import { Button } from "@/components/ui/button";
3
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
4
+ import { getLoginUrl } from "@/const";
5
+ import { Link } from "wouter";
6
+ import { ArrowRight, Zap, Code2, Brain, Cpu, Shield, TrendingUp } from "lucide-react";
7
+
8
+ export default function Home() {
9
+ const { user, isAuthenticated } = useAuth();
10
+
11
+ // Temporary bypass for login
12
+ const isDirectAccess = true;
13
+
14
+ if (isAuthenticated || isDirectAccess) {
15
+ return (
16
+ <div className="min-h-screen bg-black text-white">
17
+ {/* Navigation */}
18
+ <nav className="border-b border-green-500/20 bg-black/50 backdrop-blur-sm sticky top-0 z-40">
19
+ <div className="container mx-auto px-4 py-4 flex justify-between items-center">
20
+ <div className="flex items-center gap-3">
21
+ <div className="w-10 h-10 rounded-lg bg-gradient-to-br from-green-400 to-cyan-400 flex items-center justify-center">
22
+ <Zap className="text-black" size={20} />
23
+ </div>
24
+ <h1 className="text-xl font-bold bg-gradient-to-r from-green-400 via-cyan-400 to-blue-500 bg-clip-text text-transparent">
25
+ Hacking Factory
26
+ </h1>
27
+ </div>
28
+ <div className="flex gap-4">
29
+ <Link href="/dashboard">
30
+ <Button variant="ghost" className="text-green-400 hover:text-green-300">
31
+ Dashboard
32
+ </Button>
33
+ </Link>
34
+ <Link href="/chat">
35
+ <Button variant="ghost" className="text-cyan-400 hover:text-cyan-300">
36
+ AI Chat
37
+ </Button>
38
+ </Link>
39
+ </div>
40
+ </div>
41
+ </nav>
42
+
43
+ {/* Hero Section */}
44
+ <section className="container mx-auto px-4 py-20">
45
+ <div className="max-w-3xl mx-auto text-center mb-20">
46
+ <h2 className="text-5xl md:text-6xl font-bold mb-6 bg-gradient-to-r from-green-400 via-cyan-400 to-blue-500 bg-clip-text text-transparent">
47
+ AI-Powered Code Generation & Evaluation
48
+ </h2>
49
+ <p className="text-xl text-gray-400 mb-8">
50
+ Generate, evaluate, and optimize code with advanced AI models. Support for multiple modes and content types.
51
+ </p>
52
+ <Link href="/dashboard">
53
+ <Button className="bg-gradient-to-r from-green-500 to-cyan-500 text-black hover:from-green-600 hover:to-cyan-600 text-lg px-8 py-6">
54
+ Get Started <ArrowRight className="ml-2" size={20} />
55
+ </Button>
56
+ </Link>
57
+ </div>
58
+
59
+ {/* Features Grid */}
60
+ <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-20">
61
+ {[
62
+ {
63
+ icon: Code2,
64
+ title: "Code Generation",
65
+ description: "Generate production-ready code with Qwen AI",
66
+ color: "from-green-400 to-emerald-500",
67
+ },
68
+ {
69
+ icon: Brain,
70
+ title: "AI Evaluation",
71
+ description: "Evaluate code quality with DeepSeek analysis",
72
+ color: "from-cyan-400 to-blue-500",
73
+ },
74
+ {
75
+ icon: Cpu,
76
+ title: "Iterative Loop",
77
+ description: "Continuous improvement through AI feedback loops",
78
+ color: "from-purple-400 to-pink-500",
79
+ },
80
+ {
81
+ icon: Shield,
82
+ title: "Security Focus",
83
+ description: "Analyze code for security vulnerabilities",
84
+ color: "from-orange-400 to-red-500",
85
+ },
86
+ {
87
+ icon: TrendingUp,
88
+ title: "Performance Metrics",
89
+ description: "Track and optimize code performance",
90
+ color: "from-yellow-400 to-orange-500",
91
+ },
92
+ {
93
+ icon: Zap,
94
+ title: "Real-time Processing",
95
+ description: "Instant code generation and evaluation",
96
+ color: "from-pink-400 to-rose-500",
97
+ },
98
+ ].map((feature, idx) => {
99
+ const Icon = feature.icon;
100
+ return (
101
+ <Card key={idx} className="bg-gray-900/50 border-green-500/20 hover:border-green-500/50 transition-all">
102
+ <CardHeader>
103
+ <div className={`w-12 h-12 rounded-lg bg-gradient-to-br ${feature.color} p-2 mb-4`}>
104
+ <Icon className="text-black" size={24} />
105
+ </div>
106
+ <CardTitle className="text-green-400">{feature.title}</CardTitle>
107
+ </CardHeader>
108
+ <CardContent>
109
+ <p className="text-gray-400">{feature.description}</p>
110
+ </CardContent>
111
+ </Card>
112
+ );
113
+ })}
114
+ </div>
115
+
116
+ {/* CTA Section */}
117
+ <div className="bg-gradient-to-r from-green-500/10 to-cyan-500/10 border border-green-500/20 rounded-lg p-12 text-center">
118
+ <h3 className="text-3xl font-bold text-white mb-4">Ready to Transform Your Code?</h3>
119
+ <p className="text-gray-400 mb-8 max-w-2xl mx-auto">
120
+ Start generating and evaluating code with AI today. Create your first project and see the power of intelligent code generation.
121
+ </p>
122
+ <Link href="/dashboard">
123
+ <Button className="bg-gradient-to-r from-green-500 to-cyan-500 text-black hover:from-green-600 hover:to-cyan-600 px-8 py-6">
124
+ Launch Dashboard <ArrowRight className="ml-2" size={20} />
125
+ </Button>
126
+ </Link>
127
+ </div>
128
+ </section>
129
+ </div>
130
+ );
131
+ }
132
+
133
+ return (
134
+ <div className="min-h-screen bg-black text-white flex items-center justify-center">
135
+ <div className="text-center max-w-2xl mx-auto px-4">
136
+ <div className="w-20 h-20 rounded-lg bg-gradient-to-br from-green-400 to-cyan-400 flex items-center justify-center mx-auto mb-8">
137
+ <Zap className="text-black" size={40} />
138
+ </div>
139
+ <h1 className="text-5xl font-bold mb-4 bg-gradient-to-r from-green-400 via-cyan-400 to-blue-500 bg-clip-text text-transparent">
140
+ Hacking Factory
141
+ </h1>
142
+ <p className="text-xl text-gray-400 mb-8">
143
+ AI-Powered Code Generation & Evaluation Platform
144
+ </p>
145
+ <a href={getLoginUrl()}>
146
+ <Button className="bg-gradient-to-r from-green-500 to-cyan-500 text-black hover:from-green-600 hover:to-cyan-600 text-lg px-8 py-6">
147
+ Sign In with Manus <ArrowRight className="ml-2" size={20} />
148
+ </Button>
149
+ </a>
150
+ </div>
151
+ </div>
152
+ );
153
+ }
trpc.ts ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { NOT_ADMIN_ERR_MSG, UNAUTHED_ERR_MSG } from '@shared/const';
2
+ import { initTRPC, TRPCError } from "@trpc/server";
3
+ import superjson from "superjson";
4
+ import type { TrpcContext } from "./context";
5
+
6
+ const t = initTRPC.context<TrpcContext>().create({
7
+ transformer: superjson,
8
+ });
9
+
10
+ export const router = t.router;
11
+ export const publicProcedure = t.procedure;
12
+
13
+ const requireUser = t.middleware(async opts => {
14
+ const { ctx, next } = opts;
15
+
16
+ if (!ctx.user) {
17
+ // Temporary bypass for login: inject a mock user
18
+ const mockUser = { id: 'direct-access-user', name: 'Guest User', role: 'admin' };
19
+ return next({
20
+ ctx: {
21
+ ...ctx,
22
+ user: mockUser,
23
+ },
24
+ });
25
+ }
26
+
27
+ return next({
28
+ ctx: {
29
+ ...ctx,
30
+ user: ctx.user,
31
+ },
32
+ });
33
+ });
34
+
35
+ export const protectedProcedure = t.procedure.use(requireUser);
36
+
37
+ export const adminProcedure = t.procedure.use(
38
+ t.middleware(async opts => {
39
+ const { ctx, next } = opts;
40
+
41
+ if (!ctx.user) {
42
+ // Temporary bypass for admin check
43
+ const mockUser = { id: 'direct-access-user', name: 'Guest User', role: 'admin' };
44
+ return next({
45
+ ctx: {
46
+ ...ctx,
47
+ user: mockUser,
48
+ },
49
+ });
50
+ }
51
+
52
+ return next({
53
+ ctx: {
54
+ ...ctx,
55
+ user: ctx.user,
56
+ },
57
+ });
58
+ }),
59
+ );
useAuth.ts ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { getLoginUrl } from "@/const";
2
+ import { trpc } from "@/lib/trpc";
3
+ import { TRPCClientError } from "@trpc/client";
4
+ import { useCallback, useEffect, useMemo } from "react";
5
+
6
+ type UseAuthOptions = {
7
+ redirectOnUnauthenticated?: boolean;
8
+ redirectPath?: string;
9
+ };
10
+
11
+ export function useAuth(options?: UseAuthOptions) {
12
+ const { redirectOnUnauthenticated = false, redirectPath = getLoginUrl() } =
13
+ options ?? {};
14
+ const utils = trpc.useUtils();
15
+
16
+ const meQuery = trpc.auth.me.useQuery(undefined, {
17
+ retry: false,
18
+ refetchOnWindowFocus: false,
19
+ });
20
+
21
+ const logoutMutation = trpc.auth.logout.useMutation({
22
+ onSuccess: () => {
23
+ utils.auth.me.setData(undefined, null);
24
+ },
25
+ });
26
+
27
+ const logout = useCallback(async () => {
28
+ try {
29
+ await logoutMutation.mutateAsync();
30
+ } catch (error: unknown) {
31
+ if (
32
+ error instanceof TRPCClientError &&
33
+ error.data?.code === "UNAUTHORIZED"
34
+ ) {
35
+ return;
36
+ }
37
+ throw error;
38
+ } finally {
39
+ utils.auth.me.setData(undefined, null);
40
+ await utils.auth.me.invalidate();
41
+ }
42
+ }, [logoutMutation, utils]);
43
+
44
+ const state = useMemo(() => {
45
+ localStorage.setItem(
46
+ "manus-runtime-user-info",
47
+ JSON.stringify(meQuery.data)
48
+ );
49
+ // Temporary bypass for login
50
+ const mockUser = { id: 'direct-access-user', name: 'Guest User', role: 'admin' };
51
+ return {
52
+ user: meQuery.data ?? mockUser,
53
+ loading: false,
54
+ error: null,
55
+ isAuthenticated: true,
56
+ };
57
+ }, [
58
+ meQuery.data,
59
+ meQuery.error,
60
+ meQuery.isLoading,
61
+ logoutMutation.error,
62
+ logoutMutation.isPending,
63
+ ]);
64
+
65
+ useEffect(() => {
66
+ if (!redirectOnUnauthenticated) return;
67
+ if (meQuery.isLoading || logoutMutation.isPending) return;
68
+ if (state.user) return;
69
+ if (typeof window === "undefined") return;
70
+ if (window.location.pathname === redirectPath) return;
71
+
72
+ window.location.href = redirectPath
73
+ }, [
74
+ redirectOnUnauthenticated,
75
+ redirectPath,
76
+ logoutMutation.isPending,
77
+ meQuery.isLoading,
78
+ state.user,
79
+ ]);
80
+
81
+ return {
82
+ ...state,
83
+ refresh: () => meQuery.refetch(),
84
+ logout,
85
+ };
86
+ }