-
Notifications
You must be signed in to change notification settings - Fork 18
Prepare cli auth & access token retrieval for api key hashing #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ben-fornefeld
merged 3 commits into
main
from
change-the-dashboard-authcli-endpoint-to-always-generate-new-e2b-1581
May 15, 2025
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
dc41ac7
refactor: generate user access tokens where needed, return on cli aut…
ben-fornefeld 0d65771
add: manual selected team cookie edit on team change selection
ben-fornefeld c4442db
improve: default team retrieval for the case of multiple default teams
ben-fornefeld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { cookies } from 'next/headers' | ||
import { COOKIE_KEYS } from '@/configs/keys' | ||
import { z } from 'zod' | ||
import { ResponseCookie } from 'next/dist/compiled/@edge-runtime/cookies' | ||
|
||
const TeamStateSchema = z.object({ | ||
teamId: z.string(), | ||
teamSlug: z.string(), | ||
}) | ||
|
||
export async function POST(request: Request) { | ||
try { | ||
const body = TeamStateSchema.parse(await request.json()) | ||
|
||
const COOKIE_SETTINGS: Partial<ResponseCookie> = { | ||
path: '/', | ||
maxAge: 60 * 60 * 24 * 7, // 7 days | ||
sameSite: 'lax', | ||
secure: process.env.NODE_ENV === 'production', | ||
} | ||
|
||
const cookieStore = await cookies() | ||
|
||
cookieStore.set(COOKIE_KEYS.SELECTED_TEAM_ID, body.teamId, COOKIE_SETTINGS) | ||
cookieStore.set( | ||
COOKIE_KEYS.SELECTED_TEAM_SLUG, | ||
body.teamSlug, | ||
COOKIE_SETTINGS | ||
) | ||
|
||
return Response.json({ success: true }) | ||
} catch (error) { | ||
return Response.json({ error: 'Invalid request' }, { status: 400 }) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't this fetch cause UI unresponsiveness (meaning delay after click)?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, but this only changes cookies which means no matter the outcome, latency will be ~20 ms. the cookies kind of have to be set before doing the push/refresh, which is why we await. the router.push already has some delay in this scenario, so we don't compromise on "non-instant" navigation here anyways at the moment.