add interface

This commit is contained in:
2025-08-17 19:24:03 -03:00
parent 21f6eb030f
commit b1cff154d4
11 changed files with 320 additions and 16 deletions

View File

@@ -32,7 +32,7 @@ def session(
raise ForbiddenError('Invalid credentials')
return Response(
status_code=HTTPStatus.FOUND,
status_code=HTTPStatus.OK,
cookies=[
Cookie(
name='session_id',

View File

@@ -0,0 +1,30 @@
import * as React from "react"
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
import { CheckIcon } from "lucide-react"
import { cn } from "@/lib/utils"
function Checkbox({
className,
...props
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
return (
<CheckboxPrimitive.Root
data-slot="checkbox"
className={cn(
"peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
className
)}
{...props}
>
<CheckboxPrimitive.Indicator
data-slot="checkbox-indicator"
className="flex items-center justify-center text-current transition-none"
>
<CheckIcon className="size-3.5" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
)
}
export { Checkbox }

View File

@@ -0,0 +1,12 @@
import { createCookieSessionStorage } from 'react-router'
const { getSession, commitSession, destroySession } =
createCookieSessionStorage({
cookie: {
name: 'session_id',
httpOnly: true,
secure: true
}
})
export { getSession, commitSession, destroySession }

View File

@@ -1,5 +1,11 @@
import { type RouteConfig, index, layout } from '@react-router/dev/routes'
import {
type RouteConfig,
index,
layout,
route
} from '@react-router/dev/routes'
export default [
layout('routes/layout.tsx', [index('routes/home.tsx')])
layout('routes/layout.tsx', [index('routes/index.tsx')]),
route('/authorize', 'routes/authorize.tsx')
] satisfies RouteConfig

View File

@@ -0,0 +1,32 @@
// import { parse } from 'cookie'
import type { Route } from './+types/authorize'
export async function loader({ request, context }: Route.LoaderArgs) {
const url = new URL(request.url)
const issuerUrl = new URL('/authorize', context.cloudflare.env.ISSUER_URL)
issuerUrl.search = url.search
console.log(request.headers.get('Cookie'))
console.log(issuerUrl.toString())
try {
const r = await fetch(issuerUrl.toString(), {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Cookie: request.headers.get('Cookie')
}
})
console.log(r)
// return new Response(await r.text(), {
// status: r.status,
// headers: r.headers
// })
} catch {
return new Response(null, { status: 500 })
}
}

View File

@@ -1,14 +1,18 @@
import type { Route } from './+types/home'
import type { Route } from './+types/index'
import { isValidCPF } from '@brazilian-utils/brazilian-utils'
import { zodResolver } from '@hookform/resolvers/zod'
import { Loader2Icon } from 'lucide-react'
import { useForm } from 'react-hook-form'
import { useFetcher } from 'react-router'
import { z } from 'zod'
import { Button } from '@/components/ui/button'
import { Checkbox } from '@/components/ui/checkbox'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { useState } from 'react'
import logo from './logo.svg'
const cpf = z.string().refine(isValidCPF, { message: 'CPF inválido' })
@@ -16,7 +20,7 @@ const email = z.string().email({ message: 'Email inválido' })
const schema = z.object({
username: z.union([cpf, email]),
password: z.string()
password: z.string().nonempty()
})
type Schema = z.infer<typeof schema>
@@ -25,17 +29,44 @@ export function meta({}: Route.MetaArgs) {
return [{ title: 'EDUSEG®' }]
}
export function loader({ context }: Route.LoaderArgs) {
return { message: context.cloudflare.env.ISSUER_URL }
export async function action({ request, context }: Route.ActionArgs) {
const issuerUrl = context.cloudflare.env.ISSUER_URL
const formData = Object.fromEntries(await request.formData())
const url = new URL(request.url)
url.pathname = '/authorize'
try {
const r = await fetch(`${issuerUrl}/session`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
})
const headers = new Headers(r.headers)
headers.set('Location', url.toString())
return new Response(await r.text(), {
status: 302,
headers
})
} catch {
return new Response(null, { status: 500 })
}
}
export default function Home({ loaderData }: Route.ComponentProps) {
const { register, handleSubmit } = useForm({
export default function Index({}: Route.ComponentProps) {
const [show, setShow] = useState(false)
const fetcher = useFetcher()
const { register, handleSubmit, formState } = useForm({
resolver: zodResolver(schema)
})
const onSubmit = (data: Schema) => {
console.log(data)
const onSubmit = async (data: Schema) => {
await fetcher.submit(data, { method: 'post' })
console.log(fetcher.data)
}
return (
@@ -72,14 +103,36 @@ export default function Home({ loaderData }: Route.ComponentProps) {
<Label htmlFor="password">Senha</Label>
<a
href="#"
tabIndex={-1}
className="ml-auto text-sm underline-offset-4 hover:underline"
>
Esqueceu sua senha?
</a>
</div>
<Input id="password" {...register('password')} />
<Input
id="password"
type={show ? 'text' : 'password'}
{...register('password')}
/>
<div className="flex items-center gap-3">
<Checkbox
id="showPassword"
onClick={() => setShow((x) => !x)}
/>
<Label htmlFor="showPassword">Mostrar senha</Label>
</div>
</div>
<Button type="submit" className="w-full bg-lime-400 cursor-pointer">
<Button
type="submit"
className="w-full bg-lime-400 cursor-pointer"
disabled={formState.isSubmitting}
>
{formState.isSubmitting && (
<Loader2Icon className="animate-spin" />
)}
Entrar
</Button>
</div>

View File

@@ -10,6 +10,7 @@ export default function Layout() {
>
<ChevronLeftIcon className="size-5" /> Página inicial
</a>
<div className="w-full max-w-sm relative z-1">
<Outlet />
</div>

View File

@@ -1 +1,7 @@
<svg width="18" height="24" viewBox="0 0 18 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M16.2756 23.4353L8.93847 20.1298C8.7383 20.0015 8.48167 20.0015 8.27893 20.1298L0.941837 23.4353C0.533793 23.6945 0 23.4019 0 22.9194V1.12629C0.00256631 0.787535 0.277162 0.512939 0.615915 0.512939H16.6066C16.9454 0.512939 17.22 0.787535 17.22 1.12629V22.9194C17.22 23.4019 16.6862 23.6945 16.2781 23.4353H16.2756Z" fill="#8CD366"></path><path d="M10.7274 3.71313H3.34668V6.41803H10.7274V3.71313Z" fill="#2E3524"></path><path d="M9.42115 8.4939H3.34668V10.6496H9.42115V8.4939Z" fill="#2E3524"></path><path d="M10.7274 12.7263H3.34668V15.4312H10.7274V12.7263Z" fill="#2E3524"></path><path d="M12.9984 13.6731H12.9958C12.5111 13.6731 12.1182 14.066 12.1182 14.5508V14.5533C12.1182 15.0381 12.5111 15.431 12.9958 15.431H12.9984C13.4831 15.431 13.8761 15.0381 13.8761 14.5533V14.5508C13.8761 14.066 13.4831 13.6731 12.9984 13.6731Z" fill="#2E3524"></path></svg>
<svg width="18" height="24" viewBox="0 0 18 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M16.2756 23.4353L8.93847 20.1298C8.7383 20.0015 8.48167 20.0015 8.27893 20.1298L0.941837 23.4353C0.533793 23.6945 0 23.4019 0 22.9194V1.12629C0.00256631 0.787535 0.277162 0.512939 0.615915 0.512939H16.6066C16.9454 0.512939 17.22 0.787535 17.22 1.12629V22.9194C17.22 23.4019 16.6862 23.6945 16.2781 23.4353H16.2756Z" fill="#8CD366"></path>
<path d="M10.7274 3.71313H3.34668V6.41803H10.7274V3.71313Z" fill="#2E3524"></path>
<path d="M9.42115 8.4939H3.34668V10.6496H9.42115V8.4939Z" fill="#2E3524"></path>
<path d="M10.7274 12.7263H3.34668V15.4312H10.7274V12.7263Z" fill="#2E3524"></path>
<path d="M12.9984 13.6731H12.9958C12.5111 13.6731 12.1182 14.066 12.1182 14.5508V14.5533C12.1182 15.0381 12.5111 15.431 12.9958 15.431H12.9984C13.4831 15.431 13.8761 15.0381 13.8761 14.5533V14.5508C13.8761 14.066 13.4831 13.6731 12.9984 13.6731Z" fill="#2E3524"></path>
</svg>

Before

Width:  |  Height:  |  Size: 961 B

After

Width:  |  Height:  |  Size: 987 B

View File

@@ -9,10 +9,12 @@
"dependencies": {
"@brazilian-utils/brazilian-utils": "^1.0.0-rc.12",
"@hookform/resolvers": "^5.2.1",
"@radix-ui/react-checkbox": "^1.3.3",
"@radix-ui/react-label": "^2.1.7",
"@radix-ui/react-slot": "^1.2.3",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cookie": "^1.0.2",
"isbot": "^5.1.27",
"lucide-react": "^0.539.0",
"react": "^19.1.0",
@@ -1736,6 +1738,42 @@
"dev": true,
"license": "MIT"
},
"node_modules/@radix-ui/primitive": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/@radix-ui/primitive/-/primitive-1.1.3.tgz",
"integrity": "sha512-JTF99U/6XIjCBo0wqkU5sK10glYe27MRRsfwoiq5zzOEZLHU3A3KCMa5X/azekYRCJ0HlwI0crAXS/5dEHTzDg==",
"license": "MIT"
},
"node_modules/@radix-ui/react-checkbox": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-checkbox/-/react-checkbox-1.3.3.tgz",
"integrity": "sha512-wBbpv+NQftHDdG86Qc0pIyXk5IR3tM8Vd0nWLKDcX8nNn4nXFOFwsKuqw2okA/1D/mpaAkmuyndrPJTYDNZtFw==",
"license": "MIT",
"dependencies": {
"@radix-ui/primitive": "1.1.3",
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-context": "1.1.2",
"@radix-ui/react-presence": "1.1.5",
"@radix-ui/react-primitive": "2.1.3",
"@radix-ui/react-use-controllable-state": "1.2.2",
"@radix-ui/react-use-previous": "1.1.1",
"@radix-ui/react-use-size": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-compose-refs": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@radix-ui/react-compose-refs/-/react-compose-refs-1.1.2.tgz",
@@ -1751,6 +1789,21 @@
}
}
},
"node_modules/@radix-ui/react-context": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@radix-ui/react-context/-/react-context-1.1.2.tgz",
"integrity": "sha512-jCi/QKUM2r1Ju5a3J64TH2A5SpKAgh0LpknyqdQ4m6DCV0xJ2HG1xARRwNGPQfi1SLdLWZ1OJz6F4OMBBNiGJA==",
"license": "MIT",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-label": {
"version": "2.1.7",
"resolved": "https://registry.npmjs.org/@radix-ui/react-label/-/react-label-2.1.7.tgz",
@@ -1774,6 +1827,30 @@
}
}
},
"node_modules/@radix-ui/react-presence": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/@radix-ui/react-presence/-/react-presence-1.1.5.tgz",
"integrity": "sha512-/jfEwNDdQVBCNvjkGit4h6pMOzq8bHkopq458dPt2lMjx+eBQUohZNG9A7DtO/O5ukSbxuaNGXMjHicgwy6rQQ==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-use-layout-effect": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-primitive": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-primitive/-/react-primitive-2.1.3.tgz",
@@ -1815,6 +1892,91 @@
}
}
},
"node_modules/@radix-ui/react-use-controllable-state": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-controllable-state/-/react-use-controllable-state-1.2.2.tgz",
"integrity": "sha512-BjasUjixPFdS+NKkypcyyN5Pmg83Olst0+c6vGov0diwTEo6mgdqVR6hxcEgFuh4QrAs7Rc+9KuGJ9TVCj0Zzg==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-use-effect-event": "0.0.2",
"@radix-ui/react-use-layout-effect": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-effect-event": {
"version": "0.0.2",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-effect-event/-/react-use-effect-event-0.0.2.tgz",
"integrity": "sha512-Qp8WbZOBe+blgpuUT+lw2xheLP8q0oatc9UpmiemEICxGvFLYmHm9QowVZGHtJlGbS6A6yJ3iViad/2cVjnOiA==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-use-layout-effect": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-layout-effect": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-layout-effect/-/react-use-layout-effect-1.1.1.tgz",
"integrity": "sha512-RbJRS4UWQFkzHTTwVymMTUv8EqYhOp8dOOviLj2ugtTiXRaRQS7GLGxZTLL1jWhMeoSCf5zmcZkqTl9IiYfXcQ==",
"license": "MIT",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-previous": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-previous/-/react-use-previous-1.1.1.tgz",
"integrity": "sha512-2dHfToCj/pzca2Ck724OZ5L0EVrr3eHRNsG/b3xQJLA2hZpVCS99bLAX+hm1IHXDEnzU6by5z/5MIY794/a8NQ==",
"license": "MIT",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-size": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-size/-/react-use-size-1.1.1.tgz",
"integrity": "sha512-ewrXRDTAqAXlkl6t/fkXWNAhFX9I+CkKlw6zjEwk86RSPKwZr3xpBRso655aqYafwtnbpHLj6toFzmd6xdVptQ==",
"license": "MIT",
"dependencies": {
"@radix-ui/react-use-layout-effect": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@react-router/dev": {
"version": "7.8.0",
"resolved": "https://registry.npmjs.org/@react-router/dev/-/dev-7.8.0.tgz",

View File

@@ -14,10 +14,12 @@
"dependencies": {
"@brazilian-utils/brazilian-utils": "^1.0.0-rc.12",
"@hookform/resolvers": "^5.2.1",
"@radix-ui/react-checkbox": "^1.3.3",
"@radix-ui/react-label": "^2.1.7",
"@radix-ui/react-slot": "^1.2.3",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cookie": "^1.0.2",
"isbot": "^5.1.27",
"lucide-react": "^0.539.0",
"react": "^19.1.0",

View File

@@ -1,9 +1,9 @@
/* eslint-disable */
// Generated by Wrangler by running `wrangler types` (hash: 73d4543a7970c4847bf72b396e1b08ae)
// Generated by Wrangler by running `wrangler types` (hash: 64058b5920d46226ca8f7a7b04a89641)
// Runtime types generated with workerd@1.20250803.0 2025-04-04
declare namespace Cloudflare {
interface Env {
VALUE_FROM_CLOUDFLARE: "Hello from Cloudflare";
ISSUER_URL: "https://58tkjsb308.execute-api.sa-east-1.amazonaws.com";
}
}
interface Env extends Cloudflare.Env {}