hightjs 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +147 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  > Um framework web full‑stack moderno para Node.js, focado em simplicidade, DX e velocidade. Bundler via esbuild, hot reload, roteamento automático, APIs, autenticação JWT, CLI e muito mais.
4
4
 
5
+ <br>
6
+
7
+ [![NPM](https://img.shields.io/npm/v/hightjs.svg?style=for-the-badge&labelColor=000000)](https://www.npmjs.com/package/hightjs)
8
+
9
+ # Precisa de ajuda?
10
+ Caso tenha alguma dúvida, entre em contato por uma das redes abaixo:
11
+
12
+ [![Discord](https://img.shields.io/badge/Discord-mulinfrc-5865F2?style=for-the-badge&logo=discord&logoColor=white)](https://discord.com/users/1264710048786026588)
13
+ [![Gmail](https://img.shields.io/badge/Gmail-D14836?style=for-the-badge&logo=gmail&logoColor=white)](mailto:murillofrazaocunha@gmail.com)
14
+ [![Instagram](https://img.shields.io/badge/Instagram-E4405F?style=for-the-badge&logo=instagram&logoColor=white)](https://instagram.com/itsmuh_)
15
+ [![GitHub](https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white)](https://github.com/murillo-frazao-cunha)
16
+
5
17
  ---
6
18
 
7
19
  ## 📑 Índice
@@ -118,7 +130,7 @@ src/
118
130
  routes/
119
131
  index.tsx // Página inicial "/"
120
132
  about.tsx // Página "/about"
121
- blog[id].tsx // Rota dinâmica "/blog/123"
133
+ blog.tsx // Rota dinâmica "/blog/123"
122
134
  backend/
123
135
  routes/
124
136
  middleware.ts // Middlewares globais da pasta
@@ -152,8 +164,6 @@ export default config;
152
164
 
153
165
  ### Rotas Dinâmicas com Parâmetros
154
166
 
155
- Use colchetes: `blog/[slug].tsx` → `/blog/post`.
156
-
157
167
  ```tsx
158
168
  import {RouteConfig} from "hightjs/client";
159
169
  import React from "react";
@@ -332,7 +342,7 @@ O jeito recomendado é criar as rotas diretamente no `auth.ts` e importar onde q
332
342
  `src/auth.ts`:
333
343
 
334
344
  ```ts
335
- import { CredentialsProvider, createAuthRoutes } from 'hightjs/auth';
345
+ import { CredentialsProvider, DiscordProvider, createAuthRoutes } from 'hightjs/auth';
336
346
  import type { AuthConfig } from 'hightjs/auth';
337
347
 
338
348
  export const authConfig: AuthConfig = {
@@ -357,6 +367,13 @@ export const authConfig: AuthConfig = {
357
367
  return null;
358
368
  }
359
369
  }),
370
+ new DiscordProvider({
371
+ clientId: "ID",
372
+ clientSecret: "TOKEN",
373
+ callbackUrl: "http://localhost:3000/api/auth/callback/discord",
374
+ scope: ['identify', 'email', 'guilds'],
375
+ successUrl: "http://localhost:3000/"
376
+ })
360
377
  ],
361
378
  session: {
362
379
  strategy: 'jwt',
@@ -382,6 +399,125 @@ import { authRoutes } from "../../../auth";
382
399
  export default authRoutes;
383
400
  ```
384
401
 
402
+ ### Configurando o Frontend
403
+
404
+ Para usar autenticação no frontend, você precisa configurar o `SessionProvider` no layout:
405
+
406
+ `src/web/layout.tsx`:
407
+
408
+ ```tsx
409
+ import { SessionProvider } from 'hightjs/auth/react';
410
+
411
+ export const metadata = { title: 'Meu App', description: 'Descrição global' };
412
+
413
+ export default function Layout({ children }: { children: React.ReactNode }) {
414
+ return (
415
+ <SessionProvider>
416
+ {children}
417
+ </SessionProvider>
418
+ );
419
+ }
420
+ ```
421
+
422
+ ### Fazendo Login no Frontend
423
+
424
+ Exemplo de como implementar login com credenciais e Discord:
425
+
426
+ ```tsx
427
+ import { useSession } from 'hightjs/auth/react';
428
+ import React, { useState } from 'react';
429
+
430
+ function LoginPage() {
431
+ const { signIn } = useSession();
432
+ const [username, setUsername] = useState('');
433
+ const [password, setPassword] = useState('');
434
+ const [isLoading, setIsLoading] = useState(false);
435
+ const [error, setError] = useState<string | null>(null);
436
+
437
+ const handleDiscordLogin = async () => {
438
+ const result = await signIn('discord');
439
+ if(result) {
440
+ if (result.url != null) {
441
+ window.location.href = result.url
442
+ }
443
+ }
444
+ }
445
+
446
+ const handleLogin = async (e: React.FormEvent) => {
447
+ e.preventDefault();
448
+ setIsLoading(true);
449
+ setError(null);
450
+
451
+ try {
452
+ const result = await signIn('credentials', {
453
+ redirect: false,
454
+ username: username,
455
+ password: password,
456
+ callbackUrl: '/'
457
+ });
458
+
459
+ if (!result || result.error) {
460
+ setError('Credenciais inválidas. Verifique seus dados e senha.');
461
+ setIsLoading(false);
462
+ return;
463
+ }
464
+
465
+ } catch (err) {
466
+ setError('Ocorreu um erro inesperado. Tente novamente.');
467
+ setIsLoading(false);
468
+ }
469
+ };
470
+
471
+ return (
472
+ <div>
473
+ <form onSubmit={handleLogin}>
474
+ <input
475
+ type="text"
476
+ value={username}
477
+ onChange={(e) => setUsername(e.target.value)}
478
+ placeholder="Username"
479
+ />
480
+ <input
481
+ type="password"
482
+ value={password}
483
+ onChange={(e) => setPassword(e.target.value)}
484
+ placeholder="Password"
485
+ />
486
+ <button type="submit" disabled={isLoading}>Login</button>
487
+ </form>
488
+
489
+ <button onClick={handleDiscordLogin}>Login com Discord</button>
490
+
491
+ {error && <p style={{color: 'red'}}>{error}</p>}
492
+ </div>
493
+ );
494
+ }
495
+ ```
496
+
497
+ ### Acessando Dados do Usuário
498
+
499
+ Para acessar informações do usuário autenticado:
500
+
501
+ ```tsx
502
+ import { useSession } from 'hightjs/auth/react';
503
+
504
+ function UserProfile() {
505
+ const { data: session, status, signOut } = useSession();
506
+
507
+ if (status === 'loading') return <p>Carregando...</p>;
508
+
509
+ if (!session) return <p>Não autenticado</p>;
510
+
511
+ return (
512
+ <div>
513
+ <h1>Bem-vindo, {session.user?.name}</h1>
514
+ <p>Email: {session.user?.email}</p>
515
+ <button onClick={() => signOut()}>Logout</button>
516
+ </div>
517
+ );
518
+ }
519
+ ```
520
+
385
521
  ### Protegendo rotas backend
386
522
 
387
523
  ```ts
@@ -408,10 +544,11 @@ export default route;
408
544
 
409
545
  ### Métodos principais
410
546
 
411
- - `authRoutes.auth.signIn()`
412
- - `authRoutes.auth.signOut()`
413
- - `authRoutes.auth.getSession()`
414
- - `authRoutes.auth.isAuthenticated()`
547
+ - `signIn()` - Fazer login (credenciais ou provider)
548
+ - `signOut()` - Fazer logout
549
+ - `useSession()` - Hook para acessar sessão no frontend
550
+ - `authRoutes.auth.getSession()` - Verificar sessão no backend
551
+ - `authRoutes.auth.isAuthenticated()` - Verificar se está autenticado
415
552
 
416
553
  ---
417
554
 
@@ -505,4 +642,5 @@ Copyright 2025 itsmuzin
505
642
 
506
643
  Este projeto está licenciado sob a [Licença Apache 2.0](LICENSE).
507
644
 
508
- ---
645
+ ---
646
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hightjs",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "HightJS is a high-level framework for building web applications with ease and speed. It provides a robust set of tools and features to streamline development and enhance productivity.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",