autenticacao-e-sessao

Documents token storage, axios interceptors, and session handling for a React chess frontend.

Updated Jan 28, 2024
One-click install
npx skills add https://github.com/Thiago-Cruz-eng/KrockSide --skill autenticacao-e-sessao-thiago-cruz-eng
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: autenticacao-e-sessao
Source: https://github.com/Thiago-Cruz-eng/KrockSide/tree/main/.agents/skills/autenticacao-e-sessao
Command: npx skills add https://github.com/Thiago-Cruz-eng/KrockSide --skill autenticacao-e-sessao-thiago-cruz-eng

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? It captures the exact authentication and session model of the KrockSide React frontend so developers and agents avoid breaking the per-user token storage, misreading JWT claims, or mishandling 401 responses when touching login, useAuth, or the axios layer. ## Core Features & Use Cases - Token storage model: Documents the per-user localStorage keys (accessToken{userId}, refreshToken{userId}) plus sessionStorage.currentUserId, which enables two players in separate browser tabs. - Axios interceptor rules: Explains the single request interceptor in src/service/Api.ts, the absence of any response interceptor, and why 401s surface without retry or refresh. - JWT claims reality check: Lists the claims the backend actually emits (sub, email, name, jti, long-key role) and warns that DecodedToken.emailAddress and role are always undefined, and that role is a permission, never a piece color. - Use Case: When investigating a user being logged out unexpectedly or a 403 on validation endpoints, consult this skill to confirm token expiry behavior (60 minutes, no refresh in use) and the userId-vs-sub comparison rule before changing code. ## Quick Start Ask the agent to review the authentication and session skill before modifying Login, useAuth, or src/service/Api.ts in the KrockSide frontend.

Frequently Asked Questions about autenticacao-e-sessao

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I store JWT tokens per user in localStorage for a React app?

Use keys suffixed with the userId, such as accessToken{userId} and refreshToken{userId} in localStorage, plus sessionStorage.currentUserId to mark the active user per tab. This lets two users play in separate browser tabs with independent sessions.

How do I add an Authorization header with an axios interceptor?

Register a request interceptor on the axios instance that reads the current userId from sessionStorage, fetches the stored token, and calls config.headers.set('Authorization', `Bearer ${token}`). Use the axios 1.x AxiosHeaders API, not direct property assignment.

Why does my React app return 401 after the token expires?

The access token expires after 60 minutes and the app has no response interceptor, no automatic refresh, and no retry logic. The refresh endpoint exists but nothing calls it, so expired sessions simply start receiving 401 responses from the server.

Can I read the player color from JWT role claims?

No. The JWT role claim contains permissions like jogador or adm, never a piece color, and the DecodedToken role field is always undefined due to a long claim key. Player color comes from JoinRoomResponse.color and the PlayerJoined hub event.

Why is there no route guard on protected React routes?

App.tsx maps all routes without verification, so each screen checks session validity itself. ChessLobby validates the token before joining a room, but ChessBoard performs no check, so new authenticated screens must add explicit checks or a shared RequireAuth component.