Skip to content

Commit

Permalink
add switchToOrganization
Browse files Browse the repository at this point in the history
  • Loading branch information
cmatheson committed Nov 12, 2024
1 parent 30dafb9 commit c06330f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ The `useAuth` hook returns user information and helper functions:
- `signIn`: Redirects the user to the Hosted AuthKit sign-in page. Takes an optional `state` argument.
- `signUp`: Redirects the user to the Hosted AuthKit sign-up page. Takes an optional `state` argument.
- `signOut`: Ends the session.
- `switchToOrganization`: Switches to the given organization. Redirects to the hosted login page if switch is unsuccessful.
The following claims may be populated if the user is part of an organization:
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
"react": ">=17"
},
"dependencies": {
"@workos-inc/authkit-js": "0.6.1"
"@workos-inc/authkit-js": "0.7.0"
}
}
2 changes: 2 additions & 0 deletions src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function AuthKitProvider(props: AuthKitProviderProps) {
signIn: client.signIn.bind(client),
signUp: client.signUp.bind(client),
signOut: client.signOut.bind(client),
switchToOrganization: client.switchToOrganization.bind(client),
});
setState((prev) => ({ ...prev, isLoading: false, user }));
});
Expand Down Expand Up @@ -109,5 +110,6 @@ const NOOP_CLIENT: Client = {
signUp: async () => {},
getUser: () => null,
getAccessToken: () => Promise.reject(new LoginRequiredError()),
switchToOrganization: () => Promise.resolve(),
signOut: () => {},
};
7 changes: 6 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { createClient } from "@workos-inc/authkit-js";

export type Client = Pick<
Awaited<ReturnType<typeof createClient>>,
"signIn" | "signUp" | "getUser" | "getAccessToken" | "signOut"
| "signIn"
| "signUp"
| "getUser"
| "getAccessToken"
| "signOut"
| "switchToOrganization"
>;

export type CreateClientOptions = NonNullable<
Expand Down

0 comments on commit c06330f

Please sign in to comment.