Skip to content

Add daily Okta employee sync#123

Closed
stanleychris2 wants to merge 1 commit intomainfrom
okta-employee-sync
Closed

Add daily Okta employee sync#123
stanleychris2 wants to merge 1 commit intomainfrom
okta-employee-sync

Conversation

@stanleychris2
Copy link
Copy Markdown

Summary

  • Adds a new EmployeeInfo model linked 1:1 to User, storing employee data from Okta (name, email, title, department, start date, manager, status)
  • New /api/cron/sync-okta-users endpoint fetches all Okta users via SSWS API token and upserts into the database
  • Vercel cron runs daily at 6 AM UTC via vercel.json

Env vars needed

  • OKTA_API_TOKEN — SSWS token from Okta Admin Console (Security > API > Tokens)
  • CRON_SECRET — protects the cron endpoint (Vercel sends automatically)

Test plan

  • Tested locally against live Okta org — synced 114 employees successfully
  • Add env vars to Vercel project settings
  • Run npx prisma db push against production database
  • Verify cron fires and syncs after deploy

Made with Cursor

Fetches all users from Okta via SSWS API token and upserts into a new
EmployeeInfo model linked to User by email. Runs as a Vercel cron job
daily at 6 AM UTC, secured with CRON_SECRET.
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4176d7c. Configure here.

res: NextApiResponse
) {
const authHeader = req.headers.authorization
if (authHeader !== `Bearer ${serverEnv.CRON_SECRET}`) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty CRON_SECRET allows authentication bypass on cron endpoint

High Severity

CRON_SECRET defaults to an empty string via allowEmpty: true, default: ''. When unset, the auth check becomes authHeader !== 'Bearer ', which any external caller can satisfy by sending an Authorization: Bearer header. This effectively leaves the cron endpoint—which writes to the database and calls the Okta API—completely unprotected. The guard needs to reject requests when CRON_SECRET is empty/not configured.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4176d7c. Configure here.

Comment thread prisma/schema.prisma
provider = "mysql"
url = env("DATABASE_URL")
referentialIntegrity = "prisma"
provider = "postgresql"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Database migration breaks plain-text search queries

High Severity

Switching the database provider from mysql to postgresql breaks the existing search feature in server/routers/post.ts. Prisma's search filter on PostgreSQL uses to_tsquery, which requires tsquery syntax (e.g. hello & world). The search dialog passes raw user-typed text, which will throw a database syntax error for any multi-word query. MySQL's MATCH ... AGAINST accepted natural language input, but PostgreSQL's to_tsquery does not.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4176d7c. Configure here.

Comment thread prisma/schema.prisma
url = env("DATABASE_URL")
referentialIntegrity = "prisma"
provider = "postgresql"
url = env("DATABASE_URL")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NoAction FK constraints now enforced, blocking deletions

High Severity

Removing referentialIntegrity = "prisma" and switching to PostgreSQL means foreign key constraints are now enforced at the database level. The LikedPosts model uses onDelete: NoAction on both its post and user relations, which previously had no real enforcement (Prisma emulated FKs without creating them). Now PostgreSQL will reject any attempt to delete a Post that has likes or a User who has liked posts, breaking post and user deletion.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4176d7c. Configure here.

Comment thread prisma/schema.prisma
}

datasource db {
provider = "mysql"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought this was a pg database? https://app.planetscale.com/benchmarks/beam

@stanleychris2 stanleychris2 deleted the okta-employee-sync branch April 21, 2026 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant