-
Notifications
You must be signed in to change notification settings - Fork 460
feat(astro): Add OAuth flow components #3719
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
panteliselef
merged 8 commits into
main
from
rob/eco-42-add-support-for-authenticatewithredirectcallback
Jul 16, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a9f548d
feat(astro): Add OAuth flow component for Astro and React
wobsoriano 6dbadf7
chore(astro): Add changeset
wobsoriano fa1475e
Merge branch 'main' into rob/eco-42-add-support-for-authenticatewithr…
wobsoriano 67ebe2b
Merge branch 'main' into rob/eco-42-add-support-for-authenticatewithr…
wobsoriano 58ad906
chore(astro): Update changeset message
wobsoriano 89efbca
Merge branch 'main' into rob/eco-42-add-support-for-authenticatewithr…
wobsoriano 8efb909
Merge branch 'main' into rob/eco-42-add-support-for-authenticatewithr…
panteliselef a35c4ab
Merge branch 'main' into rob/eco-42-add-support-for-authenticatewithr…
panteliselef 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@clerk/astro": patch | ||
| --- | ||
|
|
||
| Introduce `<AuthenticateWithRedirectCallback/>` as an Astro and as a React component |
42 changes: 42 additions & 0 deletions
42
packages/astro/src/astro-components/control/AuthenticateWithRedirectCallback.astro
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,42 @@ | ||
| --- | ||
| import type { HandleOAuthCallbackParams } from '@clerk/types'; | ||
|
|
||
| type Props = HandleOAuthCallbackParams | ||
|
|
||
| import { generateSafeId } from '@clerk/astro/internal'; | ||
|
|
||
| const safeId = generateSafeId(); | ||
|
|
||
| // TODO: Move this to a prop when we implement more control components. | ||
| const functionName = 'handleRedirectCallback'; | ||
| --- | ||
|
|
||
| <div data-clerk-function-id={`clerk-${functionName}-${safeId}`}></div> | ||
|
|
||
| <script is:inline define:vars={{ props: Astro.props, functionName, safeId }}> | ||
| /** | ||
| * Store the id and the props for the Astro component in order to invoice the correct Clerk function once clerk is loaded. | ||
| * The above is handled by `invokeClerkAstroJSFunctions`. | ||
| * | ||
| * TODO: This should be moved to a separate file once we implement more control components. | ||
| */ | ||
| const setOrCreatePropMap = ({ functionName, id, props }) => { | ||
| if (!window.__astro_clerk_function_props) { | ||
| window.__astro_clerk_function_props = new Map(); | ||
| } | ||
|
|
||
| if (!window.__astro_clerk_function_props.has(functionName)) { | ||
| const _ = new Map(); | ||
| _.set(id, props); | ||
| window.__astro_clerk_function_props.set(functionName, _); | ||
| } | ||
|
|
||
| window.__astro_clerk_function_props.get(functionName)?.set(id, props); | ||
| }; | ||
|
|
||
| setOrCreatePropMap({ | ||
| functionName, | ||
| id: safeId, | ||
| props, | ||
| }); | ||
| </script> | ||
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
19 changes: 19 additions & 0 deletions
19
packages/astro/src/internal/invoke-clerk-astro-js-functions.ts
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,19 @@ | ||
| import { $clerk } from '../stores/internal'; | ||
|
|
||
| /** | ||
| * Loop through any Astro component that has requested to invoke a function and invoke it with its respective props. | ||
| */ | ||
| const invokeClerkAstroJSFunctions = () => { | ||
| const functionNames = ['handleRedirectCallback'] as const; | ||
|
|
||
| functionNames.forEach(fnName => { | ||
| const elementsOfCategory = document.querySelectorAll(`[data-clerk-function-id^="clerk-${fnName}"]`); | ||
| elementsOfCategory.forEach(el => { | ||
| const id = el.getAttribute('data-clerk-function-id'); | ||
| const props = window.__astro_clerk_function_props?.get(fnName)?.get(id!) ?? {}; | ||
| void $clerk.get()?.[fnName]?.(props); | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| export { invokeClerkAstroJSFunctions }; |
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.
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.
Added some TODOs here so that in the future when we want to implement more control components that call invoke Clerk functions, we can extract and reuse it