Skip to content

Commit ac2a809

Browse files
committed
fix mongoose issue
1 parent 665fc19 commit ac2a809

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

apps/public-api/src/controllers/userAuth.controller.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,19 @@ const assertAuthProjectReady = (project) => {
109109
* @returns {Promise<{project: Object, providerConfig: Object|null}|null>}
110110
*/
111111
const getSocialProviderConfig = async (projectId, provider) => {
112-
const selectClause = `name resources collections jwtSecret isAuthEnabled authProviders.${provider} +authProviders.${provider}.clientSecret.encrypted +authProviders.${provider}.clientSecret.iv +authProviders.${provider}.clientSecret.tag`;
112+
const selectClause = [
113+
'name',
114+
'resources',
115+
'collections',
116+
'jwtSecret',
117+
'isAuthEnabled',
118+
`authProviders.${provider}.enabled`,
119+
`authProviders.${provider}.clientId`,
120+
`authProviders.${provider}.redirectUri`,
121+
`+authProviders.${provider}.clientSecret.encrypted`,
122+
`+authProviders.${provider}.clientSecret.iv`,
123+
`+authProviders.${provider}.clientSecret.tag`,
124+
].join(' ');
113125
const project = await Project.findById(projectId).select(selectClause).lean();
114126
if (!project) return null;
115127

examples/social-demo/README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ Add these extra fields to the `users` schema:
9090
```env
9191
VITE_PUBLIC_KEY=pk_live_your_key_here
9292
VITE_API_URL=https://api.ub.bitbros.in
93-
# Required for image uploads only
93+
# Required for image uploads and GitHub social auth start
9494
VITE_PROXY_URL=http://localhost:4000/api/proxy
9595
```
9696

9797
**Server (`server/.env`)**
9898
```env
99-
# Used only by upload proxy (/storage/*)
99+
# Used by the local proxy for uploads and social auth start
100100
API_KEY=sk_live_your_key_here
101101
PORT=4000
102102
```
@@ -129,6 +129,7 @@ In GitHub:
129129
5. Copy the generated `Client ID` and `Client Secret` into urBackend Auth settings.
130130

131131
No extra client `.env` variables are required for GitHub social auth. The redirect target comes from your urBackend project `Site URL`.
132+
The local `server` must be running because the demo starts GitHub OAuth through the proxy so it can attach the required API key header.
132133

133134
### 5. Run the Application
134135
```bash
@@ -162,11 +163,12 @@ social-demo/
162163
This demo is now **PK-first** and aligned with the latest public APIs:
163164
1. **Public API Client**: Uses `pk_live_*` for `/api/userAuth/*` and `/api/data/*`.
164165
2. **RLS-protected writes**: `posts`, `comments`, `likes`, `follows`, and `profiles` require RLS so authenticated users can write with `pk_live`.
165-
3. **Upload Proxy**: A tiny local server keeps `sk_live_*` only for `/api/storage/*` uploads.
166+
3. **Upload Proxy**: A tiny local server keeps `sk_live_*` only for `/api/storage/*` uploads and starts social auth safely.
166167

167168
### Social auth flow in this demo
168169

169-
- The client sends users to `GET /api/userAuth/social/github/start` with the public key.
170+
- The client sends users to the local proxy route `GET /api/proxy/userAuth/social/github/start`.
171+
- The proxy attaches your configured API key and forwards the request to urBackend.
170172
- urBackend handles the GitHub OAuth redirect and sends users back to `<siteUrl>/auth/callback`.
171173
- The callback page exchanges the one-time `rtCode` for a refresh token, stores both tokens, and loads the signed-in user.
172174

@@ -248,6 +250,7 @@ For each writable collection (`posts`, `comments`, `likes`, `follows`, `profiles
248250
- **Profile/search pages empty?** Ensure `profiles` collection exists and RLS is enabled with `ownerField=userId`.
249251
- **403 on create/update/delete?** Ensure RLS is enabled on that collection for `pk_live` writes.
250252
- **Images not uploading?** Ensure the `server` is running and `API_KEY` is a secret key (`sk_live_...`) for `/storage/*`.
253+
- **GitHub button shows `API key not found`?** Make sure the local `server` is running and `VITE_PROXY_URL` points to it. The demo starts GitHub OAuth through the proxy, not directly from the browser.
251254
- **403 Forbidden?** Double-check your **Domain Whitelisting** settings in the urBackend dashboard.
252255
- **Data not appearing?** Verify that your collection names and field types match the schemas above exactly.
253256
- **GitHub login redirects back but does not sign in?** Make sure your urBackend project `Site URL` exactly matches the demo origin, usually `http://localhost:5173`.

examples/social-demo/client/src/lib/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export const authApi = {
129129
return response;
130130
},
131131
getSocialStartUrl: (provider) => (
132-
`${API_BASE_URL}${API_PREFIX}/userAuth/social/${encodeURIComponent(provider)}/start?key=${encodeURIComponent(PUBLIC_KEY)}`
132+
`${PROXY_URL}/userAuth/social/${encodeURIComponent(provider)}/start`
133133
),
134134
exchangeSocialAuth: async ({ token, rtCode }) => {
135135
const response = await axios.post(

0 commit comments

Comments
 (0)