Skip to content

Commit f197ffe

Browse files
dlarrodernicknisi
andauthored
feat: handleAuth > return authenticationMethod (#257)
Co-authored-by: Nick Nisi <[email protected]>
1 parent 34d7276 commit f197ffe

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/authkit-callback-route.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function handleAuth(options: HandleAuthOptions = {}) {
2525
if (code) {
2626
try {
2727
// Use the code returned to us by AuthKit and authenticate the user with WorkOS
28-
const { accessToken, refreshToken, user, impersonator, oauthTokens } =
28+
const { accessToken, refreshToken, user, impersonator, oauthTokens, authenticationMethod, organizationId } =
2929
await getWorkOS().userManagement.authenticateWithCode({
3030
clientId: WORKOS_CLIENT_ID,
3131
code,
@@ -62,7 +62,15 @@ export function handleAuth(options: HandleAuthOptions = {}) {
6262
if (!accessToken || !refreshToken) throw new Error('response is missing tokens');
6363

6464
if (onSuccess) {
65-
await onSuccess({ accessToken, refreshToken, user, impersonator, oauthTokens });
65+
await onSuccess({
66+
accessToken,
67+
refreshToken,
68+
user,
69+
impersonator,
70+
oauthTokens,
71+
authenticationMethod,
72+
organizationId,
73+
});
6674
}
6775

6876
await saveSession({ accessToken, refreshToken, user, impersonator }, request);

src/interfaces.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { OauthTokens, User } from '@workos-inc/node';
1+
import type { AuthenticationResponse, OauthTokens, User } from '@workos-inc/node';
22
import { type NextRequest } from 'next/server.js';
33

44
export interface HandleAuthOptions {
@@ -10,6 +10,8 @@ export interface HandleAuthOptions {
1010

1111
export interface HandleAuthSuccessData extends Session {
1212
oauthTokens?: OauthTokens;
13+
organizationId?: string;
14+
authenticationMethod?: AuthenticationResponse['authenticationMethod'];
1315
}
1416

1517
export interface Impersonator {

0 commit comments

Comments
 (0)