-
Notifications
You must be signed in to change notification settings - Fork 24
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 #200 from kinde-oss/peter/feat/custom-user-props
feat: user object to contain custom properties
- Loading branch information
Showing
20 changed files
with
692 additions
and
176 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
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
This file was deleted.
Oops, something went wrong.
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,28 @@ | ||
import jwtDecode from 'jwt-decode'; | ||
import {NextApiRequest, NextApiResponse} from 'next'; | ||
import {KindeAccessToken, KindeIdToken, KindeUser} from '../../types'; | ||
import {config} from '../config/index'; | ||
import {generateUserObject} from '../utils/generateUserObject'; | ||
import {sessionManager} from './sessionManager'; | ||
|
||
export const getUserFactory = | ||
(req: NextApiRequest, res: NextApiResponse) => | ||
async <T = Record<string, any>>(): Promise<KindeUser<T>> => { | ||
try { | ||
const idToken = jwtDecode( | ||
(await sessionManager(req, res).getSessionItem('id_token')) as string | ||
) as KindeIdToken; | ||
|
||
const accessToken = jwtDecode( | ||
(await sessionManager(req, res).getSessionItem( | ||
'access_token' | ||
)) as string | ||
) as KindeAccessToken; | ||
return generateUserObject(idToken, accessToken) as KindeUser<T>; | ||
} catch (error) { | ||
if (config.isDebugMode) { | ||
console.debug('getUser', error); | ||
} | ||
return null; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
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,44 @@ | ||
import {sessionManager} from './sessionManager'; | ||
import {kindeClient} from './kindeServerClient'; | ||
import {config} from '../config/index'; | ||
import {NextApiRequest, NextApiResponse} from 'next'; | ||
import {KindeOrganizations} from '../../types'; | ||
|
||
export const getUserOrganizationsFactory = | ||
(req?: NextApiRequest, res?: NextApiResponse) => | ||
async (): Promise<KindeOrganizations | null> => { | ||
try { | ||
const session = sessionManager(req, res); | ||
const userOrgs = await kindeClient.getUserOrganizations(session); | ||
const orgNames = (await kindeClient.getClaimValue( | ||
session, | ||
'organizations', | ||
'id_token' | ||
)) as {id: string; name: string}[]; | ||
|
||
const hasuraOrgCodes = (await kindeClient.getClaimValue( | ||
session, | ||
'x-hasura-org-codes', | ||
'id_token' | ||
)) as string[]; | ||
|
||
const hasuraOrganizations = (await kindeClient.getClaimValue( | ||
session, | ||
'x-hasura-organizations', | ||
'id_token' | ||
)) as {id: string; name: string}[]; | ||
|
||
return { | ||
orgCodes: [...userOrgs.orgCodes, ...hasuraOrgCodes], | ||
orgs: [...orgNames, ...hasuraOrganizations].map((org) => ({ | ||
code: org?.id, | ||
name: org?.name | ||
})) | ||
}; | ||
} catch (error) { | ||
if (config.isDebugMode) { | ||
console.debug('getUserOrganization error:', error); | ||
} | ||
return null; | ||
} | ||
}; |
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 was deleted.
Oops, something went wrong.
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,10 @@ | ||
import { | ||
createKindeServerClient, | ||
GrantType | ||
} from '@kinde-oss/kinde-typescript-sdk'; | ||
import {config} from '../config/index'; | ||
|
||
export const kindeClient = createKindeServerClient( | ||
GrantType.AUTHORIZATION_CODE, | ||
config.clientOptions | ||
); |
Oops, something went wrong.