第一次提交
This commit is contained in:
50
auth-portal/src/app/api/runtime/login/route.ts
Normal file
50
auth-portal/src/app/api/runtime/login/route.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import type { TokenResponse } from '@/types/auth';
|
||||
import { HttpError, callDeployControl, callInstanceApi, normalizeTokenResponse } from '@/lib/runtime-control';
|
||||
|
||||
function errorStatus(error: unknown): number {
|
||||
if (error instanceof HttpError) {
|
||||
return error.status;
|
||||
}
|
||||
return 500;
|
||||
}
|
||||
|
||||
function errorDetail(error: unknown): string {
|
||||
if (error instanceof HttpError) {
|
||||
return error.message;
|
||||
}
|
||||
return error instanceof Error ? error.message : 'login failed';
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = (await request.json()) as {
|
||||
username?: string;
|
||||
password?: string;
|
||||
};
|
||||
const username = body.username?.trim() || '';
|
||||
const password = body.password || '';
|
||||
|
||||
if (!username || !password) {
|
||||
return NextResponse.json({ detail: 'username and password are required' }, { status: 400 });
|
||||
}
|
||||
|
||||
const routing = await callDeployControl<{
|
||||
api_base_url?: string;
|
||||
frontend_base_url?: string;
|
||||
public_url?: string;
|
||||
}>('/api/instances/resolve', { username });
|
||||
|
||||
const response = await callInstanceApi<TokenResponse>(routing.api_base_url || '', '/api/auth/login', {
|
||||
username,
|
||||
password,
|
||||
});
|
||||
|
||||
return NextResponse.json(normalizeTokenResponse(response, routing));
|
||||
} catch (error) {
|
||||
const status = errorStatus(error);
|
||||
const detail = status === 404 || status === 401 ? '用户名或密码错误' : errorDetail(error);
|
||||
return NextResponse.json({ detail }, { status: status === 404 ? 401 : status });
|
||||
}
|
||||
}
|
||||
55
auth-portal/src/app/api/runtime/register/route.ts
Normal file
55
auth-portal/src/app/api/runtime/register/route.ts
Normal file
@ -0,0 +1,55 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
import type { TokenResponse } from '@/types/auth';
|
||||
import { HttpError, callDeployControl, callInstanceApi, normalizeTokenResponse } from '@/lib/runtime-control';
|
||||
|
||||
function errorStatus(error: unknown): number {
|
||||
if (error instanceof HttpError) {
|
||||
return error.status;
|
||||
}
|
||||
return 500;
|
||||
}
|
||||
|
||||
function errorDetail(error: unknown): string {
|
||||
if (error instanceof HttpError) {
|
||||
return error.message;
|
||||
}
|
||||
return error instanceof Error ? error.message : 'registration failed';
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = (await request.json()) as {
|
||||
username?: string;
|
||||
email?: string;
|
||||
password?: string;
|
||||
};
|
||||
const username = body.username?.trim() || '';
|
||||
const email = body.email?.trim() || '';
|
||||
const password = body.password || '';
|
||||
|
||||
if (!username || !password) {
|
||||
return NextResponse.json({ detail: 'username and password are required' }, { status: 400 });
|
||||
}
|
||||
|
||||
const routing = await callDeployControl<{
|
||||
api_base_url?: string;
|
||||
frontend_base_url?: string;
|
||||
public_url?: string;
|
||||
}>('/api/instances/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
});
|
||||
|
||||
const response = await callInstanceApi<TokenResponse>(routing.api_base_url || '', '/api/auth/register', {
|
||||
username,
|
||||
email,
|
||||
password,
|
||||
});
|
||||
|
||||
return NextResponse.json(normalizeTokenResponse(response, routing));
|
||||
} catch (error) {
|
||||
return NextResponse.json({ detail: errorDetail(error) }, { status: errorStatus(error) });
|
||||
}
|
||||
}
|
||||
266
auth-portal/src/app/globals.css
Normal file
266
auth-portal/src/app/globals.css
Normal file
@ -0,0 +1,266 @@
|
||||
:root {
|
||||
--bg: #f4efe6;
|
||||
--bg-strong: #e6d8bf;
|
||||
--panel: rgba(23, 26, 31, 0.88);
|
||||
--panel-border: rgba(255, 255, 255, 0.1);
|
||||
--text: #f7f1e7;
|
||||
--muted: rgba(247, 241, 231, 0.72);
|
||||
--accent: #ff8d3a;
|
||||
--accent-strong: #ff6b00;
|
||||
--danger: #ff8787;
|
||||
--input: rgba(255, 255, 255, 0.08);
|
||||
--input-focus: rgba(255, 141, 58, 0.28);
|
||||
--shadow: 0 40px 90px rgba(26, 24, 21, 0.28);
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
margin: 0;
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "IBM Plex Sans", "Avenir Next", "Segoe UI", sans-serif;
|
||||
color: var(--text);
|
||||
background:
|
||||
radial-gradient(circle at top left, rgba(255, 141, 58, 0.28), transparent 28%),
|
||||
radial-gradient(circle at right center, rgba(19, 104, 93, 0.18), transparent 24%),
|
||||
linear-gradient(135deg, var(--bg) 0%, #d6c09b 45%, var(--bg-strong) 100%);
|
||||
}
|
||||
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
button,
|
||||
input {
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.portal-page {
|
||||
min-height: 100vh;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 32px 18px;
|
||||
}
|
||||
|
||||
.portal-shell {
|
||||
width: min(980px, 100%);
|
||||
display: grid;
|
||||
grid-template-columns: 1.05fr 0.95fr;
|
||||
overflow: hidden;
|
||||
border-radius: 28px;
|
||||
box-shadow: var(--shadow);
|
||||
background: rgba(255, 250, 241, 0.45);
|
||||
backdrop-filter: blur(12px);
|
||||
}
|
||||
|
||||
.portal-brand {
|
||||
position: relative;
|
||||
min-height: 620px;
|
||||
padding: 48px 42px;
|
||||
color: #26180d;
|
||||
background:
|
||||
linear-gradient(160deg, rgba(255, 240, 217, 0.82), rgba(255, 220, 174, 0.64)),
|
||||
linear-gradient(135deg, #ffd7a3, #f3b15f);
|
||||
}
|
||||
|
||||
.portal-brand::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: 22px;
|
||||
border-radius: 22px;
|
||||
border: 1px solid rgba(38, 24, 13, 0.08);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.portal-kicker {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 8px 12px;
|
||||
border-radius: 999px;
|
||||
background: rgba(38, 24, 13, 0.08);
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.portal-title {
|
||||
margin: 26px 0 14px;
|
||||
font-size: clamp(36px, 5vw, 60px);
|
||||
line-height: 0.95;
|
||||
letter-spacing: -0.06em;
|
||||
}
|
||||
|
||||
.portal-copy {
|
||||
max-width: 460px;
|
||||
font-size: 16px;
|
||||
line-height: 1.65;
|
||||
color: rgba(38, 24, 13, 0.78);
|
||||
}
|
||||
|
||||
.portal-notes {
|
||||
margin-top: 34px;
|
||||
display: grid;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.portal-note {
|
||||
padding: 16px 18px;
|
||||
border-radius: 18px;
|
||||
background: rgba(255, 255, 255, 0.45);
|
||||
border: 1px solid rgba(38, 24, 13, 0.08);
|
||||
}
|
||||
|
||||
.portal-note strong {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.portal-panel {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 32px;
|
||||
background:
|
||||
linear-gradient(180deg, rgba(23, 26, 31, 0.96), rgba(12, 14, 17, 0.94));
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
width: min(440px, 100%);
|
||||
padding: 34px;
|
||||
border-radius: 24px;
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--panel-border);
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
|
||||
}
|
||||
|
||||
.auth-card h1 {
|
||||
margin: 0 0 10px;
|
||||
font-size: 34px;
|
||||
letter-spacing: -0.05em;
|
||||
}
|
||||
|
||||
.auth-card p {
|
||||
margin: 0;
|
||||
color: var(--muted);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.auth-form {
|
||||
margin-top: 26px;
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.field {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.field label {
|
||||
font-size: 14px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.field input {
|
||||
width: 100%;
|
||||
padding: 14px 16px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 14px;
|
||||
color: var(--text);
|
||||
background: var(--input);
|
||||
outline: none;
|
||||
transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease;
|
||||
}
|
||||
|
||||
.field input:focus {
|
||||
border-color: rgba(255, 141, 58, 0.65);
|
||||
background: rgba(255, 255, 255, 0.11);
|
||||
box-shadow: 0 0 0 5px var(--input-focus);
|
||||
}
|
||||
|
||||
.error-text {
|
||||
min-height: 22px;
|
||||
font-size: 14px;
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.primary-button {
|
||||
width: 100%;
|
||||
padding: 14px 18px;
|
||||
border: none;
|
||||
border-radius: 16px;
|
||||
cursor: pointer;
|
||||
color: #26180d;
|
||||
background: linear-gradient(135deg, var(--accent), var(--accent-strong));
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.01em;
|
||||
transition: transform 140ms ease, filter 140ms ease, opacity 140ms ease;
|
||||
}
|
||||
|
||||
.primary-button:hover {
|
||||
transform: translateY(-1px);
|
||||
filter: brightness(1.02);
|
||||
}
|
||||
|
||||
.primary-button:disabled {
|
||||
cursor: wait;
|
||||
opacity: 0.68;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.auth-footer {
|
||||
margin-top: 20px;
|
||||
color: var(--muted);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.auth-footer a {
|
||||
color: #ffd7a3;
|
||||
}
|
||||
|
||||
.status-panel {
|
||||
margin-top: 18px;
|
||||
padding: 14px 16px;
|
||||
border-radius: 16px;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
@media (max-width: 920px) {
|
||||
.portal-shell {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.portal-brand {
|
||||
min-height: auto;
|
||||
padding-bottom: 30px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.portal-page {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.portal-brand,
|
||||
.portal-panel {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
padding: 24px 20px;
|
||||
}
|
||||
}
|
||||
|
||||
20
auth-portal/src/app/layout.tsx
Normal file
20
auth-portal/src/app/layout.tsx
Normal file
@ -0,0 +1,20 @@
|
||||
import './globals.css';
|
||||
import type { Metadata } from 'next';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Boardware Genius Auth Portal',
|
||||
description: 'Dedicated login and registration portal for nanobot containers.',
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<html lang="zh-CN">
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
100
auth-portal/src/app/login/page.tsx
Normal file
100
auth-portal/src/app/login/page.tsx
Normal file
@ -0,0 +1,100 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { useState } from 'react';
|
||||
|
||||
import { buildFrontendHandoffUrl, login, withNext } from '@/lib/auth-client';
|
||||
|
||||
export default function LoginPage() {
|
||||
const searchParams = useSearchParams();
|
||||
const nextPath = searchParams?.get('next') || '/';
|
||||
|
||||
const [username, setUsername] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setLoading(true);
|
||||
setError('');
|
||||
|
||||
try {
|
||||
const response = await login(username, password);
|
||||
window.location.replace(buildFrontendHandoffUrl(response, nextPath));
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : '登录失败,请稍后重试');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<main className="portal-page">
|
||||
<section className="portal-shell">
|
||||
<div className="portal-brand">
|
||||
<div className="portal-kicker">Auth Portal</div>
|
||||
<h1 className="portal-title">Boardware Genius</h1>
|
||||
<p className="portal-copy">
|
||||
这个入口只负责鉴权。成功后会把你直接送到为你分配的专属实例 URL,后续前后端请求都留在那套容器里。
|
||||
</p>
|
||||
<div className="portal-notes">
|
||||
<div className="portal-note">
|
||||
<strong>容器边界</strong>
|
||||
登录注册先经过独立 auth portal,再跳到专属实例。一用户一套前后端容器不变。
|
||||
</div>
|
||||
<div className="portal-note">
|
||||
<strong>目标页面</strong>
|
||||
当前登录完成后将回到:<code>{nextPath}</code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="portal-panel">
|
||||
<div className="auth-card">
|
||||
<h1>登录</h1>
|
||||
<p>输入已有账号,认证完成后直接进入目标容器前端。</p>
|
||||
|
||||
<form className="auth-form" onSubmit={handleSubmit}>
|
||||
<div className="field">
|
||||
<label htmlFor="username">用户名</label>
|
||||
<input
|
||||
id="username"
|
||||
value={username}
|
||||
onChange={(event) => setUsername(event.target.value)}
|
||||
autoComplete="username"
|
||||
placeholder="例如:bwgdi"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="field">
|
||||
<label htmlFor="password">密码</label>
|
||||
<input
|
||||
id="password"
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
autoComplete="current-password"
|
||||
placeholder="输入密码"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="error-text">{error}</div>
|
||||
|
||||
<button className="primary-button" type="submit" disabled={loading}>
|
||||
{loading ? '登录中...' : '登录并进入容器'}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div className="auth-footer">
|
||||
还没有账号? <Link href={withNext('/register', nextPath)}>去注册</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
6
auth-portal/src/app/page.tsx
Normal file
6
auth-portal/src/app/page.tsx
Normal file
@ -0,0 +1,6 @@
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
export default function HomePage() {
|
||||
redirect('/login');
|
||||
}
|
||||
|
||||
134
auth-portal/src/app/register/page.tsx
Normal file
134
auth-portal/src/app/register/page.tsx
Normal file
@ -0,0 +1,134 @@
|
||||
'use client';
|
||||
|
||||
import Link from 'next/link';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { useState } from 'react';
|
||||
|
||||
import { buildFrontendHandoffUrl, register, withNext } from '@/lib/auth-client';
|
||||
|
||||
export default function RegisterPage() {
|
||||
const searchParams = useSearchParams();
|
||||
const nextPath = searchParams?.get('next') || '/mcp';
|
||||
|
||||
const [username, setUsername] = useState('');
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [confirmPassword, setConfirmPassword] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setLoading(true);
|
||||
setError('');
|
||||
|
||||
try {
|
||||
if (password !== confirmPassword) {
|
||||
throw new Error('两次输入的密码不一致');
|
||||
}
|
||||
const response = await register(username, email, password);
|
||||
window.location.replace(buildFrontendHandoffUrl(response, nextPath));
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : '注册失败,请稍后重试');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<main className="portal-page">
|
||||
<section className="portal-shell">
|
||||
<div className="portal-brand">
|
||||
<div className="portal-kicker">Auth Portal</div>
|
||||
<h1 className="portal-title">Create Runtime</h1>
|
||||
<p className="portal-copy">
|
||||
注册不仅建立登录账号,还会触发专属实例创建和 backend 身份分配。认证完成后会直接进入你的专属 URL。
|
||||
</p>
|
||||
<div className="portal-notes">
|
||||
<div className="portal-note">
|
||||
<strong>注册结果</strong>
|
||||
deploy-control 会创建实例,AuthZ 再补齐 backend 身份,auth portal 最后把你转交到该实例前端。
|
||||
</div>
|
||||
<div className="portal-note">
|
||||
<strong>目标页面</strong>
|
||||
当前注册完成后将回到:<code>{nextPath}</code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="portal-panel">
|
||||
<div className="auth-card">
|
||||
<h1>注册</h1>
|
||||
<p>为当前容器创建登录账号,并完成 backend 身份初始化。</p>
|
||||
|
||||
<form className="auth-form" onSubmit={handleSubmit}>
|
||||
<div className="field">
|
||||
<label htmlFor="username">用户名</label>
|
||||
<input
|
||||
id="username"
|
||||
value={username}
|
||||
onChange={(event) => setUsername(event.target.value)}
|
||||
autoComplete="username"
|
||||
placeholder="例如:bwgdi"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="field">
|
||||
<label htmlFor="email">邮箱</label>
|
||||
<input
|
||||
id="email"
|
||||
type="email"
|
||||
value={email}
|
||||
onChange={(event) => setEmail(event.target.value)}
|
||||
autoComplete="email"
|
||||
placeholder="例如:steven@example.com"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="field">
|
||||
<label htmlFor="password">密码</label>
|
||||
<input
|
||||
id="password"
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
autoComplete="new-password"
|
||||
placeholder="设置密码"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="field">
|
||||
<label htmlFor="confirmPassword">确认密码</label>
|
||||
<input
|
||||
id="confirmPassword"
|
||||
type="password"
|
||||
value={confirmPassword}
|
||||
onChange={(event) => setConfirmPassword(event.target.value)}
|
||||
autoComplete="new-password"
|
||||
placeholder="再次输入密码"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="error-text">{error}</div>
|
||||
|
||||
<button className="primary-button" type="submit" disabled={loading}>
|
||||
{loading ? '注册中...' : '注册并进入容器'}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div className="auth-footer">
|
||||
已有账号? <Link href={withNext('/login', nextPath)}>去登录</Link>
|
||||
</div>
|
||||
|
||||
<div className="status-panel">
|
||||
Portal 会先调用部署机接口创建实例,再把浏览器跳到实例自己的 URL。
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user