-
Notifications
You must be signed in to change notification settings - Fork 1
feat(core): introduce createAuthClient API
#114
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
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9b076a2
feat(core): introduce `createAuthClient` API
halvaradop 71ec9e1
chore(nextjs): adopt createAuthClient API in Next.js routers
halvaradop 5ffd21e
chore(examples): adopt client API
halvaradop 0cc0b0c
feat(core): add `redirect` and `redirectURI` options to `signIn` action
halvaradop 6592c5d
chore(examples): update integration apps
halvaradop 7ae74ab
chore(core): improve and refactor signIn and signOut implementations
halvaradop 62ff41e
chore: apply coderabbit
halvaradop 7e3d0a1
chore: apply coderabbit
halvaradop 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
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 |
|---|---|---|
| @@ -1,68 +1,6 @@ | ||
| import { createClient, type Session, type LiteralUnion, type BuiltInOAuthProvider } from "@aura-stack/auth" | ||
| import { createAuthClient } from "@aura-stack/auth/client" | ||
|
|
||
| export const client = createClient({ | ||
| baseURL: typeof window !== "undefined" ? window.location.origin : "http://localhost:3000", | ||
| export const authClient = createAuthClient({ | ||
| basePath: "/api/auth", | ||
| cache: "no-store", | ||
| credentials: "include", | ||
| baseURL: "http://localhost:5173", | ||
| }) | ||
|
|
||
| const getCSRFToken = async (): Promise<string | null> => { | ||
| try { | ||
| const response = await client.get("/csrfToken") | ||
| if (!response.ok) return null | ||
| const data = await response.json() | ||
| return data.csrfToken | ||
| } catch (error) { | ||
| console.log("[error:client] getCSRFToken", error) | ||
| return null | ||
| } | ||
| } | ||
|
|
||
| const getSession = async (): Promise<Session | null> => { | ||
| try { | ||
| const response = await client.get("/session") | ||
| if (!response.ok) return null | ||
| const session = await response.json() | ||
| return session?.authenticated ? session : null | ||
| } catch (error) { | ||
| console.log("[error:client] getSession", error) | ||
| return null | ||
| } | ||
| } | ||
|
|
||
| const signIn = async (provider: LiteralUnion<BuiltInOAuthProvider>, redirectTo: string = "/") => { | ||
| const baseURL = window.location.origin | ||
| window.location.href = `${baseURL}/api/auth/signIn/${provider}?${new URLSearchParams({ redirectTo })}` | ||
| } | ||
|
|
||
| const signOut = async (redirectTo: string = "/") => { | ||
| try { | ||
| const csrfToken = await getCSRFToken() | ||
| if (!csrfToken) { | ||
| console.log("[error:client] signOut - No CSRF token found") | ||
| return null | ||
| } | ||
| const response = await client.post("/signOut", { | ||
| searchParams: { | ||
| redirectTo, | ||
| token_type_hint: "session_token", | ||
| }, | ||
| headers: { | ||
| "X-CSRF-Token": csrfToken, | ||
| }, | ||
| }) | ||
| const json = await response.json() | ||
| return json | ||
| } catch (error) { | ||
| console.log("[error:client] signOut", error) | ||
| return null | ||
| } | ||
| } | ||
|
|
||
| export const createAuthClient = { | ||
| getCSRFToken, | ||
| getSession, | ||
| signIn, | ||
| signOut, | ||
| } | ||
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 |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| import { createAuthClient } from "@/lib/index" | ||
| import type { authClient } from "@/lib/client" | ||
| import type { Session } from "@aura-stack/auth" | ||
|
|
||
| export interface AuthContextValue { | ||
| session: Session | null | ||
| isLoading: boolean | ||
| isAuthenticated: boolean | ||
| signIn: (typeof createAuthClient)["signIn"] | ||
| signOut: (typeof createAuthClient)["signOut"] | ||
| signIn: typeof authClient.signIn | ||
| signOut: typeof authClient.signOut | ||
| } |
File renamed without changes.
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
Oops, something went wrong.
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.