🎉 first commit

This commit is contained in:
LIlGG
2025-09-24 13:06:25 +08:00
commit 1f4fb103e9
409 changed files with 61222 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
import type { LoaderFunctionArgs } from '@remix-run/node';
import { data } from '@remix-run/node';
import { getAuthError } from '~/lib/.server/auth';
/**
* 检查认证错误信息的路由
*
* 从会话中读取认证错误信息,并在响应中返回
* 同时会清除错误信息,确保它只显示一次
*/
export async function checkErrorLoader({ request }: LoaderFunctionArgs) {
const { errorMessage, headers } = await getAuthError(request);
return data(
{
errorMessage,
},
{
headers,
},
);
}

View File

@@ -0,0 +1,41 @@
import type { LoaderFunctionArgs } from '@remix-run/node';
import { logto } from '~/lib/.server/auth';
import { checkErrorLoader } from './check-error.server';
import { userLoader } from './user.server';
export const loader = async (args: LoaderFunctionArgs) => {
const { params } = args;
switch (params.action) {
case 'check-error':
return checkErrorLoader(args);
case 'user':
return userLoader(args);
default:
/**
* 处理认证路由
* 支持的路由:
* - /api/auth/sign-in - 登录
* - /api/auth/callback - 登录回调
* - /api/auth/sign-out - 登出
*/
return logto.handleAuthRoutes({
'sign-in': {
path: '/api/auth/sign-in',
redirectBackTo: '/api/auth/callback',
},
'sign-in-callback': {
path: '/api/auth/callback',
redirectBackTo: '/',
},
'sign-out': {
path: '/api/auth/sign-out',
redirectBackTo: '/',
},
'sign-up': {
path: '/api/auth/sign-up',
redirectBackTo: '/api/auth/callback',
},
})(args);
}
};

View File

@@ -0,0 +1,16 @@
import { data, type LoaderFunctionArgs } from '@remix-run/node';
import { getUser } from '~/lib/.server/auth';
/**
* 用户信息API端点
* 返回用户认证状态和用户信息
*/
export async function userLoader({ request }: LoaderFunctionArgs) {
// 使用服务端 getUser 函数获取用户上下文
const userContext = await getUser(request);
return data({
isAuthenticated: userContext.isAuthenticated,
claims: userContext.isAuthenticated ? userContext.userInfo : null,
});
}