refactor(client): use generated API client and hooks
Signed-off-by: Noa Virellia <noa@requiem.garden>
This commit is contained in:
@@ -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">
|
||||
|
||||
Reference in New Issue
Block a user