-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from storybookjs/kasper/redirect-boundary
Bunch of fixes and improvements
- Loading branch information
Showing
38 changed files
with
1,317 additions
and
902 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,28 +1,32 @@ | ||
import { TestRunnerConfig, getStoryContext } from '@storybook/test-runner'; | ||
import { MINIMAL_VIEWPORTS } from '@storybook/addon-viewport'; | ||
import { TestRunnerConfig, getStoryContext } from '@storybook/test-runner' | ||
import { MINIMAL_VIEWPORTS } from '@storybook/addon-viewport' | ||
|
||
const DEFAULT_VIEWPORT_SIZE = { width: 1280, height: 720 }; | ||
const DEFAULT_VIEWPORT_SIZE = { width: 1280, height: 720 } | ||
|
||
const config: TestRunnerConfig = { | ||
async preVisit(page, story) { | ||
const context = await getStoryContext(page, story); | ||
const viewportName = context.parameters?.viewport?.defaultViewport; | ||
const viewportParameter = MINIMAL_VIEWPORTS[viewportName]; | ||
const context = await getStoryContext(page, story) | ||
const viewportName = context.parameters?.viewport?.defaultViewport | ||
const viewportParameter = MINIMAL_VIEWPORTS[viewportName] | ||
|
||
if (viewportParameter) { | ||
if ( | ||
viewportParameter && | ||
viewportParameter.styles && | ||
typeof viewportParameter.styles === 'object' | ||
) { | ||
const viewportSize = Object.entries(viewportParameter.styles).reduce( | ||
(acc, [screen, size]) => ({ | ||
...acc, | ||
// make sure your viewport config in Storybook only uses numbers, not percentages | ||
[screen]: parseInt(size), | ||
}), | ||
{} | ||
); | ||
{} as { width: number; height: number }, | ||
) | ||
|
||
page.setViewportSize(viewportSize); | ||
page.setViewportSize(viewportSize) | ||
} else { | ||
page.setViewportSize(DEFAULT_VIEWPORT_SIZE); | ||
page.setViewportSize(DEFAULT_VIEWPORT_SIZE) | ||
} | ||
}, | ||
}; | ||
export default config; | ||
} | ||
export default config |
This file contains 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 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 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,57 @@ | ||
import { redirect } from 'next/navigation' | ||
import { cookies } from 'next/headers' | ||
import { createUserCookie, userCookieKey } from '#lib/session' | ||
|
||
const CLIENT_ID = process.env.OAUTH_CLIENT_KEY | ||
const CLIENT_SECRET = process.env.OAUTH_CLIENT_SECRET | ||
|
||
export async function GET(request: Request) { | ||
const code = new URL(request.url).searchParams.get('code') | ||
|
||
let token = '' | ||
try { | ||
const data = await ( | ||
await fetch('https://github.com/login/oauth/access_token', { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
client_id: CLIENT_ID, | ||
client_secret: CLIENT_SECRET, | ||
code, | ||
}), | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
}) | ||
).json() | ||
|
||
const accessToken = data.access_token | ||
|
||
// Let's also fetch the user info and store it in the session. | ||
if (accessToken) { | ||
const userInfo = await ( | ||
await fetch('https://api.github.com/user', { | ||
method: 'GET', | ||
headers: { | ||
Authorization: `token ${accessToken}`, | ||
Accept: 'application/json', | ||
}, | ||
}) | ||
).json() | ||
|
||
token = userInfo.login | ||
} | ||
} catch (err: any) { | ||
console.error(err) | ||
redirect('/') | ||
} | ||
|
||
if (!token) { | ||
console.error('Github authorization failed') | ||
redirect('/') | ||
} | ||
|
||
const cookieValue = await createUserCookie(token) | ||
cookies().set(userCookieKey, `${cookieValue}; Secure; HttpOnly`) | ||
redirect('/') | ||
} |
This file contains 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 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
Oops, something went wrong.