refactor(client): use generated API client and hooks
All checks were successful
Client CMS Check Build (NixCN CMS) TeamCity build finished
Backend Check Build (NixCN CMS) TeamCity build finished

Signed-off-by: Noa Virellia <noa@requiem.garden>
This commit is contained in:
2026-01-29 11:43:46 +08:00
parent f898243de5
commit a0f6087d3e
38 changed files with 4076 additions and 217 deletions

View File

@@ -3,9 +3,10 @@ import { zodValidator } from '@tanstack/zod-adapter';
import { isNil } from 'lodash-es';
import z from 'zod';
import { LoginForm } from '@/components/login-form';
import { axiosClient } from '@/lib/axios';
import { generateOAuthState } from '@/lib/random';
import { getToken } from '@/lib/token';
import { useExchangeToken } from '@/hooks/data/useExchangeToken';
import { useEffect } from 'react';
const authorizeSchema = z.object({
response_type: z.literal('code').default('code'),
@@ -24,22 +25,21 @@ export const Route = createFileRoute('/authorize')({
function RouteComponent() {
const token = getToken();
const oauthParams = Route.useSearch();
const mutation = useExchangeToken();
/**
* Auth by Token Flow
*/
if (!isNil(token)) {
axiosClient.post<{ redirect_uri: string }>('/auth/exchange', {
client_id: oauthParams.client_id,
redirect_uri: oauthParams.redirect_uri,
state: oauthParams.state,
}).then((res) => {
window.location.href = res.data.redirect_uri;
}).catch((e) => {
console.error(e);
return 'Token exchange failed';
});
return 'Redirecting';
}
useEffect(() => {
if (!isNil(token) && mutation.isIdle) {
mutation.mutate({
body: {
client_id: oauthParams.client_id,
redirect_uri: oauthParams.redirect_uri,
state: oauthParams.state,
}
});
}
}, [token, mutation.isIdle]);
return (
<div className="bg-background flex min-h-svh flex-col items-center justify-center gap-6 p-6 md:p-10">
<div className="w-full max-w-sm">