You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix Google sign-in loop: restore Amplify env vars, fix DynamoDB table keys, fix permanent dynamoFailed flag
- Restored all 16 Amplify env vars (update-app --environment-variables replaces, not appends)
- Recreated autisense-users table with PK=id (was userId)
- Recreated autisense-auth-sessions table with PK=token (was sessionToken)
- Changed dynamoFailed from permanent boolean to 30s cooldown timer
- Updated SETUP_GUIDE.md with warnings and changelog
|`AWS_REGION`| Auto (Lambda) | Lambda execution region |
77
-
|`AWS_ACCESS_KEY_ID`| Auto (Lambda IAM) | IAM role credentials |
78
-
|`AWS_SECRET_ACCESS_KEY`| Auto (Lambda IAM) | IAM role credentials |
79
-
|`AWS_SESSION_TOKEN`| Auto (Lambda IAM) | IAM role session token |
76
+
|`APP_ACCESS_KEY_ID`| Amplify + next.config.ts | IAM user access key (Amplify blocks `AWS_*`) |
77
+
|`APP_SECRET_ACCESS_KEY`| Amplify + next.config.ts | IAM user secret key |
78
+
|`APP_REGION`| Amplify + next.config.ts | AWS region for SDK clients |
80
79
81
80
### Google OAuth Setup
82
81
@@ -92,23 +91,21 @@ The redirect URI is constructed from `NEXT_PUBLIC_APP_URL` + `/api/auth/callback
92
91
93
92
## AWS SDK Credential Handling
94
93
95
-
**NEVER pass explicit credentials to AWS SDK clients in API routes.**
94
+
Amplify WEB_COMPUTE does **not** expose IAM role credentials to the SSR Lambda runtime. We use custom-named env vars (`APP_ACCESS_KEY_ID`, `APP_SECRET_ACCESS_KEY`, `APP_REGION`) because Amplify reserves the `AWS_*` prefix.
95
+
96
+
All SDK clients use the shared helper in `app/lib/aws/credentials.ts`:
96
97
97
98
```ts
98
-
// WRONG — breaks on Amplify Lambda (missing sessionToken)
// CORRECT — SDK auto-detects IAM role credentials (including session token)
108
-
newDynamoDBClient({ region: "ap-south-1" });
109
106
```
110
107
111
-
On Amplify Lambda, the IAM execution role provides **temporary STS credentials** that include `AWS_SESSION_TOKEN`. The default SDK credential provider chain handles this automatically. Passing explicit `accessKeyId`/`secretAccessKey` without `sessionToken` will cause auth failures.
108
+
This falls back to the SDK default provider chain when `APP_*` vars are not set (e.g., local dev with `AWS_*` in `.env.local`).
112
109
113
110
---
114
111
@@ -151,3 +148,84 @@ Then redeploy.
151
148
**Cause:** React 19 strict lint rules (`react-hooks/*`) introduced in `eslint-config-next`.
152
149
153
150
**Fix:** Rules are configured in `eslint.config.mjs`. If new violations appear after updating Next.js, check if hooks ordering or ref patterns need adjustment.
151
+
152
+
### Google sign-in enters a redirect loop
153
+
154
+
**Cause:** DynamoDB auth tables have wrong primary key names, or env vars were wiped.
155
+
156
+
**Fix:** Verify table schemas match what the code expects:
157
+
-`autisense-users`: PK = `id` (string), GSI = `email-index` on `email`
158
+
-`autisense-auth-sessions`: PK = `token` (string), TTL on `expiresAt`
159
+
160
+
Also verify all 16 Amplify env vars are set (see below).
161
+
162
+
---
163
+
164
+
## Critical Warnings
165
+
166
+
### `aws amplify update-app --environment-variables` REPLACES ALL vars
167
+
168
+
**The `--environment-variables` flag REPLACES the entire env var map.** It does not append.
# Copy all existing vars, add your new one, then update with the full list
181
+
```
182
+
183
+
### DynamoDB Table Key Schema Must Match Code
184
+
185
+
The auth code in `app/lib/auth/dynamodb.ts` uses these exact key names:
186
+
-`autisense-users` table: PK must be `id` (NOT `userId`)
187
+
-`autisense-auth-sessions` table: PK must be `token` (NOT `sessionToken`)
188
+
189
+
If tables are created with different key names, all DynamoDB operations fail silently and auth falls back to in-memory (which doesn't persist across Lambda instances).
0 commit comments