Skip to content

Eng 2586 portal poc#5447

Draft
mcstepp wants to merge 12 commits intomainfrom
ENG-2586-portal-poc
Draft

Eng 2586 portal poc#5447
mcstepp wants to merge 12 commits intomainfrom
ENG-2586-portal-poc

Conversation

@mcstepp
Copy link
Collaborator

@mcstepp mcstepp commented Mar 24, 2026

What does this PR do?

Fixes # (issue)

If there is not an issue for this, please create one first. This is used to tracking purposes and also helps us understand why this PR exists

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • Test A
  • Test B

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Ran make fmt on /go directory
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

@linear
Copy link

linear bot commented Mar 24, 2026

@vercel
Copy link

vercel bot commented Mar 24, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dashboard Ready Ready Preview, Comment Mar 24, 2026 7:48pm

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 24, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0aa2488a-aaba-498d-ab44-fff11346da4b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ENG-2586-portal-poc

Comment @coderabbitai help to get the list of available commands and usage tips.

if err != nil {
if db.IsNotFound(err) {
return nil, fault.New("invalid or expired portal session",
fault.Code(codes.Auth.Authentication.KeyNotFound.URN()),
Copy link
Member

Choose a reason for hiding this comment

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

We should define custom errors for this and not re-use Authentication.KeyNotFound aka we can add a new one for portal stuff in pkg/codes/unkey_auth.go

Comment on lines +28 to +43
row, err := db.Query.FindValidPortalSession(ctx, s.db.RO(), token)
if err != nil {
if db.IsNotFound(err) {
return nil, fault.New("invalid or expired portal session",
fault.Code(codes.Auth.Authentication.KeyNotFound.URN()),
fault.Internal("portal session not found or expired"),
fault.Public("The portal session is invalid or has expired."),
)
}
return nil, fault.Wrap(err,
fault.Code(codes.App.Internal.ServiceUnavailable.URN()),
fault.Internal("database error finding portal session"),
fault.Public("Failed to validate portal session."),
)
}

Copy link
Member

Choose a reason for hiding this comment

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

should be cached, see key verifier for reference

Comment on lines +46 to +52
if err := json.Unmarshal(row.Permissions, &permissions); err != nil {
return nil, fault.Wrap(err,
fault.Code(codes.App.Internal.UnexpectedError.URN()),
fault.Internal("failed to unmarshal portal session permissions"),
fault.Public("An internal error occurred."),
)
}
Copy link
Member

Choose a reason for hiding this comment

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

we could just use our db.UnmarshalNullableJSONTo

Comment on lines +6714 to +6731
"401":
content:
application/json:
schema:
$ref: '#/components/schemas/UnauthorizedErrorResponse'
description: Unauthorized — session is invalid, expired, or already exchanged
"429":
content:
application/problem+json:
schema:
$ref: '#/components/schemas/TooManyRequestsErrorResponse'
description: Too Many Requests
"500":
content:
application/json:
schema:
$ref: '#/components/schemas/InternalServerErrorResponse'
description: Internal server error
Copy link
Member

Choose a reason for hiding this comment

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

we shouldnt mix application/problem+json and application/json

which I started but we really want application/problem+json for errors

Comment on lines +62 to +76
if req.ExternalID == "" {
return fault.New("externalId is required",
fault.Code(codes.App.Validation.InvalidInput.URN()),
fault.Internal("missing externalId"),
fault.Public("externalId is required."),
)
}

if len(req.Permissions) == 0 {
return fault.New("permissions is required",
fault.Code(codes.App.Validation.InvalidInput.URN()),
fault.Internal("missing permissions"),
fault.Public("permissions array is required."),
)
}
Copy link
Member

Choose a reason for hiding this comment

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

I dont think we need this, the openapi validation should take core of this

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.

2 participants