@luanpdd/kit-mcp 1.31.0 → 1.33.0
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.
- package/README.md +1 -1
- package/kit/COMPATIBILITY.md +5 -0
- package/kit/agents/designer-ui.md +216 -0
- package/kit/agents/supabase-auth-bootstrapper.md +15 -1
- package/kit/agents/supabase-auth-hook-writer.md +418 -0
- package/kit/agents/supabase-mfa-implementer.md +439 -0
- package/kit/agents/supabase-oauth-server-implementer.md +507 -0
- package/kit/agents/supabase-social-auth-implementer.md +451 -0
- package/kit/agents/supabase-sso-saml-architect.md +549 -0
- package/kit/commands/supabase.md +21 -1
- package/kit/file-manifest.json +29 -6
- package/kit/skills/supabase-auth-hardening/SKILL.md +674 -0
- package/kit/skills/supabase-auth-hooks/SKILL.md +875 -0
- package/kit/skills/supabase-auth-methods/SKILL.md +486 -0
- package/kit/skills/supabase-auth-sessions/SKILL.md +579 -0
- package/kit/skills/supabase-auth-ssr/SKILL.md +60 -14
- package/kit/skills/supabase-enterprise-sso-saml/SKILL.md +545 -0
- package/kit/skills/supabase-jwt-signing-keys/SKILL.md +399 -0
- package/kit/skills/supabase-mfa/SKILL.md +488 -0
- package/kit/skills/supabase-oauth-server/SKILL.md +537 -0
- package/kit/skills/supabase-social-oauth/SKILL.md +480 -0
- package/kit/skills/supabase-third-party-auth/SKILL.md +450 -0
- package/kit/skills/ui-anti-padroes-ia/SKILL.md +261 -0
- package/kit/skills/ui-contexto-produto/SKILL.md +248 -0
- package/kit/skills/ui-cor-estrategia/SKILL.md +213 -0
- package/kit/skills/ui-critica-auditoria/SKILL.md +260 -0
- package/kit/skills/ui-motion-funcional/SKILL.md +264 -0
- package/kit/skills/ui-ritmo-espacial/SKILL.md +259 -0
- package/kit/skills/ui-tipografia/SKILL.md +211 -0
- package/package.json +1 -1
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: supabase-third-party-auth
|
|
3
|
+
description: Use ao integrar Clerk, Firebase, Auth0, AWS Cognito ou WorkOS como provedor de autenticação primário junto ao Supabase, via opção accessToken no createClient.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Supabase — Third-Party Auth (Clerk, Firebase, Auth0, Cognito, WorkOS)
|
|
7
|
+
|
|
8
|
+
## Quando usar
|
|
9
|
+
|
|
10
|
+
LLM carrega esta skill quando o projeto usar um **provedor de autenticação externo** (Clerk, Firebase Auth, Auth0, AWS Cognito, WorkOS) e precisar integrar com o banco de dados Supabase mantendo RLS funcional.
|
|
11
|
+
|
|
12
|
+
Trigger phrases:
|
|
13
|
+
|
|
14
|
+
- "Clerk Supabase", "Firebase auth Supabase"
|
|
15
|
+
- "Auth0 Supabase", "AWS Cognito Supabase"
|
|
16
|
+
- "WorkOS Supabase", "third-party auth"
|
|
17
|
+
- "accessToken option Supabase client"
|
|
18
|
+
- "JWT externo Supabase", "outro provedor de auth com RLS"
|
|
19
|
+
- "integrar Clerk com banco Supabase"
|
|
20
|
+
|
|
21
|
+
## Princípio canônico
|
|
22
|
+
|
|
23
|
+
O Supabase Third-Party Auth permite que JWTs emitidos por provedores externos sejam aceitos pelo PostgREST — assim, RLS policies continuam funcionando com `auth.uid()` e `auth.jwt()` sem duplicar usuários no `auth.users` do Supabase.
|
|
24
|
+
|
|
25
|
+
**Como funciona:**
|
|
26
|
+
|
|
27
|
+
1. O provedor externo emite um JWT assinado com chaves assimétricas (RS256/ES256)
|
|
28
|
+
2. Você configura a integração no Supabase apontando para o OIDC Issuer Discovery URL do provedor
|
|
29
|
+
3. Supabase valida o JWT contra as chaves públicas do provedor (cache de ~30min)
|
|
30
|
+
4. PostgREST aceita o token e `auth.uid()` retorna o `sub` do JWT do provedor
|
|
31
|
+
5. RLS policies funcionam normalmente
|
|
32
|
+
|
|
33
|
+
**Quando usar third-party auth vs Supabase Auth nativo:**
|
|
34
|
+
|
|
35
|
+
| Cenário | Recomendação |
|
|
36
|
+
|---------|--------------|
|
|
37
|
+
| Já usa Clerk/Auth0 em produção e quer adicionar Supabase como banco | Third-party auth |
|
|
38
|
+
| App novo sem auth definida | Supabase Auth nativo |
|
|
39
|
+
| Precisa de features avançadas de MFA/SSO do provedor externo | Third-party auth |
|
|
40
|
+
| Quer unificar auth + banco na mesma plataforma | Supabase Auth nativo |
|
|
41
|
+
|
|
42
|
+
**Limitação importante:** não é possível desabilitar o Supabase Auth ao usar third-party auth — ambos coexistem.
|
|
43
|
+
|
|
44
|
+
## Limitações e requisitos
|
|
45
|
+
|
|
46
|
+
1. **JWT DEVE ser assimétrico com header `kid`** — HS256 e PS256 não são suportados
|
|
47
|
+
2. **Chaves do provedor em cache por ~30min** — rotação de chaves pode causar janela de falha
|
|
48
|
+
3. **Claim `role: 'authenticated'` obrigatório** — todos os usuários precisam deste claim no JWT; sem ele, o PostgREST trata como `anon`
|
|
49
|
+
4. **Supabase Auth não pode ser desabilitado** — third-party e nativo coexistem sempre
|
|
50
|
+
5. **Self-hosting exige RLS RESTRICTIVE por `iss`/`aud`** — sem isso, qualquer JWT assimétrico seria aceito
|
|
51
|
+
|
|
52
|
+
## Setup — Habilitar a integração
|
|
53
|
+
|
|
54
|
+
### Via Dashboard
|
|
55
|
+
|
|
56
|
+
`Authentication > Third-Party Auth` → Adicionar provedor → Selecionar tipo → Preencher campos.
|
|
57
|
+
|
|
58
|
+
### Via `config.toml` (desenvolvimento local)
|
|
59
|
+
|
|
60
|
+
```toml
|
|
61
|
+
# Clerk
|
|
62
|
+
[auth.third_party.clerk]
|
|
63
|
+
enabled = true
|
|
64
|
+
domain = "meu-tenant.clerk.accounts.dev"
|
|
65
|
+
|
|
66
|
+
# Firebase
|
|
67
|
+
[auth.third_party.firebase]
|
|
68
|
+
enabled = true
|
|
69
|
+
project_id = "meu-projeto-firebase"
|
|
70
|
+
|
|
71
|
+
# Auth0
|
|
72
|
+
[auth.third_party.auth0]
|
|
73
|
+
enabled = true
|
|
74
|
+
tenant = "meu-tenant.us.auth0.com"
|
|
75
|
+
|
|
76
|
+
# AWS Cognito
|
|
77
|
+
[auth.third_party.aws_cognito]
|
|
78
|
+
enabled = true
|
|
79
|
+
user_pool_id = "us-east-1_XXXXXXXX"
|
|
80
|
+
user_pool_region = "us-east-1"
|
|
81
|
+
|
|
82
|
+
# WorkOS
|
|
83
|
+
[auth.third_party.workos]
|
|
84
|
+
enabled = true
|
|
85
|
+
issuer = "https://api.workos.com"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Client Setup — Opção `accessToken`
|
|
89
|
+
|
|
90
|
+
**Regra canônica:** usar a opção `accessToken` async no `createClient` — NÃO injetar o JWT via header `Authorization` custom.
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
// lib/supabase/client.ts — Clerk como exemplo
|
|
94
|
+
import { createClient } from '@supabase/supabase-js'
|
|
95
|
+
import { useAuth } from '@clerk/nextjs'
|
|
96
|
+
|
|
97
|
+
export function createClerkSupabaseClient() {
|
|
98
|
+
const { getToken } = useAuth()
|
|
99
|
+
|
|
100
|
+
return createClient(
|
|
101
|
+
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
|
102
|
+
process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!, // sb_publishable_... ou anon key
|
|
103
|
+
{
|
|
104
|
+
accessToken: async () => {
|
|
105
|
+
// Retorna o JWT do Clerk — Supabase usa para autenticar requests
|
|
106
|
+
return getToken()
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
// Server Component / Route Handler (Next.js App Router com Clerk)
|
|
115
|
+
import { auth } from '@clerk/nextjs/server'
|
|
116
|
+
import { createClient } from '@supabase/supabase-js'
|
|
117
|
+
|
|
118
|
+
export async function createServerClient() {
|
|
119
|
+
const { getToken } = await auth()
|
|
120
|
+
|
|
121
|
+
return createClient(
|
|
122
|
+
process.env.SUPABASE_URL!,
|
|
123
|
+
process.env.SUPABASE_PUBLISHABLE_KEY!,
|
|
124
|
+
{
|
|
125
|
+
accessToken: async () => {
|
|
126
|
+
return getToken()
|
|
127
|
+
},
|
|
128
|
+
}
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Por provedor — Configuração específica
|
|
134
|
+
|
|
135
|
+
### Clerk
|
|
136
|
+
|
|
137
|
+
Clerk inclui automaticamente `role: 'authenticated'` via claim `role`.
|
|
138
|
+
|
|
139
|
+
```toml
|
|
140
|
+
[auth.third_party.clerk]
|
|
141
|
+
enabled = true
|
|
142
|
+
domain = "meu-tenant.clerk.accounts.dev"
|
|
143
|
+
# domain é o issuer — obtido em Clerk Dashboard > Domains
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
// Clerk — client com accessToken
|
|
148
|
+
import { useAuth } from '@clerk/nextjs'
|
|
149
|
+
import { createClient } from '@supabase/supabase-js'
|
|
150
|
+
|
|
151
|
+
function useSupabaseClient() {
|
|
152
|
+
const { getToken } = useAuth()
|
|
153
|
+
|
|
154
|
+
return createClient(URL, PUBLISHABLE_KEY, {
|
|
155
|
+
accessToken: async () => getToken(), // JWT do Clerk
|
|
156
|
+
})
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**RLS com Clerk:** `auth.uid()` retorna o Clerk user ID (string `user_xxx`).
|
|
161
|
+
|
|
162
|
+
```sql
|
|
163
|
+
-- Policy usando ID do Clerk
|
|
164
|
+
create policy "Usuário vê seus dados" on public.perfis
|
|
165
|
+
for select to authenticated
|
|
166
|
+
using (auth.uid()::text = clerk_user_id);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Firebase Auth
|
|
170
|
+
|
|
171
|
+
Firebase JWT **não inclui** `role: 'authenticated'` por padrão — **todos os usuários precisam** deste claim via:
|
|
172
|
+
|
|
173
|
+
**Opção A — Blocking Functions (onCreate):**
|
|
174
|
+
```js
|
|
175
|
+
// functions/index.js
|
|
176
|
+
const { beforeUserCreated } = require('firebase-functions/v2/identity')
|
|
177
|
+
|
|
178
|
+
exports.beforecreated = beforeUserCreated((event) => {
|
|
179
|
+
return {
|
|
180
|
+
customClaims: { role: 'authenticated' },
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
**Opção B — Custom claim em usuários existentes (Admin SDK):**
|
|
186
|
+
```ts
|
|
187
|
+
// scripts/migrate-firebase-users.ts
|
|
188
|
+
import admin from 'firebase-admin'
|
|
189
|
+
|
|
190
|
+
const users = await admin.auth().listUsers()
|
|
191
|
+
for (const user of users.users) {
|
|
192
|
+
await admin.auth().setCustomUserClaims(user.uid, { role: 'authenticated' })
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
```toml
|
|
197
|
+
[auth.third_party.firebase]
|
|
198
|
+
enabled = true
|
|
199
|
+
project_id = "meu-projeto-firebase"
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Self-hosting com Firebase — RLS RESTRICTIVE obrigatório:**
|
|
203
|
+
|
|
204
|
+
```sql
|
|
205
|
+
-- Sem isto, qualquer JWT Firebase seria aceito (incluindo de outros projetos)
|
|
206
|
+
create policy "Apenas usuários deste projeto Firebase" on public.dados
|
|
207
|
+
as restrictive for all to authenticated
|
|
208
|
+
using (
|
|
209
|
+
auth.jwt() ->> 'iss' = 'https://securetoken.google.com/meu-projeto-firebase'
|
|
210
|
+
AND auth.jwt() ->> 'aud' = 'meu-projeto-firebase'
|
|
211
|
+
);
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Auth0
|
|
215
|
+
|
|
216
|
+
Auth0 JWT vem em **dois sabores** — usar o **ID token** (não o access token):
|
|
217
|
+
|
|
218
|
+
- Access token do Auth0: audience é a API Auth0, não validado pelo Supabase
|
|
219
|
+
- **ID token do Auth0**: contém claims de usuário, validado como JWT OIDC
|
|
220
|
+
|
|
221
|
+
O claim `role` precisa ser adicionado via Auth0 Action:
|
|
222
|
+
|
|
223
|
+
```js
|
|
224
|
+
// Auth0 Action — onExecutePostLogin
|
|
225
|
+
exports.onExecutePostLogin = async (event, api) => {
|
|
226
|
+
api.idToken.setCustomClaim('role', 'authenticated')
|
|
227
|
+
// Adicionar outros claims customizados se necessário
|
|
228
|
+
api.idToken.setCustomClaim('org_id', event.organization?.id)
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
```toml
|
|
233
|
+
[auth.third_party.auth0]
|
|
234
|
+
enabled = true
|
|
235
|
+
tenant = "meu-tenant.us.auth0.com"
|
|
236
|
+
# Auth0 OIDC Discovery: https://meu-tenant.us.auth0.com/.well-known/openid-configuration
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
```ts
|
|
240
|
+
// Client com Auth0 — usar getIdTokenClaims para obter o ID token
|
|
241
|
+
import { useAuth0 } from '@auth0/auth0-react'
|
|
242
|
+
|
|
243
|
+
function useSupabaseClient() {
|
|
244
|
+
const { getIdTokenClaims } = useAuth0()
|
|
245
|
+
|
|
246
|
+
return createClient(URL, PUBLISHABLE_KEY, {
|
|
247
|
+
accessToken: async () => {
|
|
248
|
+
const claims = await getIdTokenClaims()
|
|
249
|
+
return claims?.__raw ?? null // __raw = ID token JWT string
|
|
250
|
+
},
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
**HS256 e PS256 não são suportados** pelo Supabase — configurar Auth0 para usar RS256.
|
|
256
|
+
|
|
257
|
+
### AWS Cognito
|
|
258
|
+
|
|
259
|
+
Cognito requer custom claim `role: 'authenticated'` via **Pre-Token Generation Lambda**:
|
|
260
|
+
|
|
261
|
+
```python
|
|
262
|
+
# Lambda — pre_token_generation_v2
|
|
263
|
+
def handler(event, context):
|
|
264
|
+
event['response']['claimsAndScopeOverrideDetails'] = {
|
|
265
|
+
'idTokenGeneration': {
|
|
266
|
+
'claimsToAddOrOverride': {
|
|
267
|
+
'role': 'authenticated'
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return event
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
```toml
|
|
275
|
+
[auth.third_party.aws_cognito]
|
|
276
|
+
enabled = true
|
|
277
|
+
user_pool_id = "us-east-1_XXXXXXXX"
|
|
278
|
+
user_pool_region = "us-east-1"
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
```ts
|
|
282
|
+
// Client com Cognito (usando AWS Amplify)
|
|
283
|
+
import { fetchAuthSession } from 'aws-amplify/auth'
|
|
284
|
+
|
|
285
|
+
function createCognitoSupabaseClient() {
|
|
286
|
+
return createClient(URL, PUBLISHABLE_KEY, {
|
|
287
|
+
accessToken: async () => {
|
|
288
|
+
const session = await fetchAuthSession()
|
|
289
|
+
// Usar ID token (inclui custom claims configurados na Lambda)
|
|
290
|
+
return session.tokens?.idToken?.toString() ?? null
|
|
291
|
+
},
|
|
292
|
+
})
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
```sql
|
|
297
|
+
-- RLS com Cognito — auth.uid() retorna o sub do usuário Cognito
|
|
298
|
+
create policy "Usuário vê seus dados" on public.dados
|
|
299
|
+
for select to authenticated
|
|
300
|
+
using (
|
|
301
|
+
auth.uid()::text = cognito_user_sub
|
|
302
|
+
AND auth.jwt() ->> 'iss' LIKE '%cognito-idp.%'
|
|
303
|
+
);
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### WorkOS
|
|
307
|
+
|
|
308
|
+
WorkOS usa JWT Template para configurar o claim `role`:
|
|
309
|
+
|
|
310
|
+
```toml
|
|
311
|
+
[auth.third_party.workos]
|
|
312
|
+
enabled = true
|
|
313
|
+
issuer = "https://api.workos.com"
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
No WorkOS Dashboard: `JWT Templates` → criar template com claim:
|
|
317
|
+
|
|
318
|
+
```json
|
|
319
|
+
{
|
|
320
|
+
"role": "authenticated",
|
|
321
|
+
"org_id": "{{organization.id}}",
|
|
322
|
+
"email": "{{user.email}}"
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
// Client com WorkOS
|
|
328
|
+
import { useAuth } from '@workos-inc/authkit-nextjs'
|
|
329
|
+
|
|
330
|
+
function createWorkOSSupabaseClient() {
|
|
331
|
+
const { getAccessToken } = useAuth()
|
|
332
|
+
|
|
333
|
+
return createClient(URL, PUBLISHABLE_KEY, {
|
|
334
|
+
accessToken: async () => {
|
|
335
|
+
return getAccessToken()
|
|
336
|
+
},
|
|
337
|
+
})
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
## Verificar JWT no servidor com getClaims()
|
|
342
|
+
|
|
343
|
+
Ao usar `@supabase/ssr` no servidor, use `getClaims()` para validar o JWT do provedor externo:
|
|
344
|
+
|
|
345
|
+
```ts
|
|
346
|
+
// app/api/dados/route.ts
|
|
347
|
+
import { createServerClient } from '@supabase/ssr'
|
|
348
|
+
import { cookies } from 'next/headers'
|
|
349
|
+
|
|
350
|
+
export async function GET() {
|
|
351
|
+
const supabase = createServerClient(
|
|
352
|
+
process.env.SUPABASE_URL!,
|
|
353
|
+
process.env.SUPABASE_PUBLISHABLE_KEY!,
|
|
354
|
+
{ cookies: { getAll: () => cookies().getAll() } }
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
// getClaims() valida assinatura contra JWKS do provedor
|
|
358
|
+
const { data: { claims }, error } = await supabase.auth.getClaims()
|
|
359
|
+
if (error || !claims) return new Response('Não autorizado', { status: 401 })
|
|
360
|
+
|
|
361
|
+
// claims.sub = user ID do provedor, claims.email, etc.
|
|
362
|
+
return Response.json({ userId: claims.sub })
|
|
363
|
+
}
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
## Regras absolutas
|
|
367
|
+
|
|
368
|
+
1. **JWT do provedor deve ser assimétrico com header `kid`** — HS256 e PS256 não são suportados; verificar configuração do provedor antes de integrar
|
|
369
|
+
2. **Todos os usuários precisam do claim `role: 'authenticated'`** — sem ele, PostgREST trata como `anon` e RLS policies para `authenticated` não se aplicam
|
|
370
|
+
3. **Usar a opção `accessToken` do client, NÃO header Authorization custom** — a opção `accessToken` é o mecanismo oficial; header custom não funciona com `@supabase/ssr`
|
|
371
|
+
4. **Self-hosting exige RLS RESTRICTIVE por `iss`/`aud`** — sem isolamento por issuer, qualquer JWT assimétrico válido de outro projeto seria aceito
|
|
372
|
+
5. **Nunca usar `getSession()` no servidor** — usar `getClaims()` que valida a assinatura; `getSession()` apenas decodifica sem validar
|
|
373
|
+
6. **Nunca usar `auth-helpers-nextjs`** — usar `@supabase/ssr` exclusivamente
|
|
374
|
+
|
|
375
|
+
## Anti-patterns
|
|
376
|
+
|
|
377
|
+
### Anti-pattern 1: JWT HS256 do provedor
|
|
378
|
+
|
|
379
|
+
**Errado:**
|
|
380
|
+
```
|
|
381
|
+
Auth0 configurado com algoritmo HS256 → token enviado ao Supabase → erro de validação
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
**Por quê:** Supabase Third-Party Auth valida JWTs contra a JWKS pública do provedor (assimétrico). HS256 usa shared secret — não há JWKS público, validação falha.
|
|
385
|
+
|
|
386
|
+
**Certo:** configurar o provedor para emitir tokens RS256 ou ES256; em Auth0, verificar `Applications > Advanced Settings > JSON Web Token > Algorithm = RS256`.
|
|
387
|
+
|
|
388
|
+
### Anti-pattern 2: Esquecer o claim `role: 'authenticated'`
|
|
389
|
+
|
|
390
|
+
**Errado:**
|
|
391
|
+
```ts
|
|
392
|
+
// Firebase — usuário criado sem custom claim
|
|
393
|
+
await admin.auth().createUser({ email: 'user@exemplo.com' })
|
|
394
|
+
// JWT gerado: { sub: '...', email: '...', iat: ..., exp: ... }
|
|
395
|
+
// FALTA: role: 'authenticated' → PostgREST trata como anon!
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
**Por quê:** sem `role: 'authenticated'`, as RLS policies para o role `authenticated` não são avaliadas — usuário vê apenas o que políticas `anon` permitem (geralmente nada).
|
|
399
|
+
|
|
400
|
+
**Certo:** configurar blocking function (Firebase), Action (Auth0), Lambda (Cognito) ou JWT Template (WorkOS) para incluir `role: 'authenticated'` em todos os tokens.
|
|
401
|
+
|
|
402
|
+
### Anti-pattern 3: Header Authorization custom em vez de `accessToken`
|
|
403
|
+
|
|
404
|
+
**Errado:**
|
|
405
|
+
```ts
|
|
406
|
+
const supabase = createClient(URL, KEY, {
|
|
407
|
+
global: {
|
|
408
|
+
headers: {
|
|
409
|
+
Authorization: `Bearer ${clerkToken}`, // ERRADO — não funciona com ssr
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
})
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
**Por quê:** injetar `Authorization` global quebra o refresh automático de token e não funciona com `@supabase/ssr` (que gerencia headers por request). A opção `accessToken` é chamada em cada request, garantindo tokens frescos.
|
|
416
|
+
|
|
417
|
+
**Certo:** sempre usar a opção `accessToken: async () => getToken()` no `createClient`.
|
|
418
|
+
|
|
419
|
+
### Anti-pattern 4: Self-hosting sem RLS RESTRICTIVE por iss/aud
|
|
420
|
+
|
|
421
|
+
**Errado:**
|
|
422
|
+
```sql
|
|
423
|
+
-- Self-hosting sem isolamento de issuer
|
|
424
|
+
-- Qualquer JWT RS256 de qualquer projeto Firebase seria aceito!
|
|
425
|
+
create policy "Usuários podem ver seus dados" on public.dados
|
|
426
|
+
for select to authenticated
|
|
427
|
+
using (auth.uid() = user_id);
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
**Por quê:** em self-hosting, Supabase pode ser configurado para aceitar JWTs de múltiplos issuers. Sem filtrar por `iss`/`aud`, token de outro projeto do mesmo provedor seria válido.
|
|
431
|
+
|
|
432
|
+
**Certo:** adicionar policy RESTRICTIVE verificando `iss` e `aud`:
|
|
433
|
+
|
|
434
|
+
```sql
|
|
435
|
+
create policy "Apenas Firebase deste projeto" on public.dados
|
|
436
|
+
as restrictive for all to authenticated
|
|
437
|
+
using (
|
|
438
|
+
auth.jwt() ->> 'iss' = 'https://securetoken.google.com/meu-projeto'
|
|
439
|
+
AND auth.jwt() ->> 'aud' = 'meu-projeto'
|
|
440
|
+
);
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
## Ver também
|
|
444
|
+
|
|
445
|
+
- [supabase-oauth-server](../supabase-oauth-server/SKILL.md) — Supabase como identity provider (direção oposta)
|
|
446
|
+
- [supabase-jwt-signing-keys](../supabase-jwt-signing-keys/SKILL.md) — algoritmos assimétricos e JWKS
|
|
447
|
+
- [supabase-enterprise-sso-saml](../supabase-enterprise-sso-saml/SKILL.md) — SSO SAML enterprise nativo do Supabase
|
|
448
|
+
- [supabase-auth-methods](../supabase-auth-methods/SKILL.md) — panorama de todos os métodos de auth
|
|
449
|
+
- [supabase-auth-ssr](../supabase-auth-ssr/SKILL.md) — @supabase/ssr, getClaims(), cookies
|
|
450
|
+
- [supabase-rls-policies](../supabase-rls-policies/SKILL.md) — RLS com auth.uid() e auth.jwt() claims
|