-
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.
- Loading branch information
1 parent
d768cbf
commit 186b0ff
Showing
40 changed files
with
165 additions
and
331 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
import {sessionManager} from './sessionManager'; | ||
|
||
export const getAccessTokenFactory = (req, res) => async () => { | ||
return await sessionManager(req, res).getSessionItem('access_token_payload'); | ||
}; |
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,12 @@ | ||
import {getFlagFactory} from './getFlag'; | ||
|
||
export const getBooleanFlagFactory = | ||
(req, res) => async (code, defaultValue) => { | ||
try { | ||
const flag = await getFlagFactory(req, res)(code, defaultValue, 'b'); | ||
return flag.value; | ||
} catch (err) { | ||
console.error(err); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {sessionManager} from './sessionManager'; | ||
import {kindeClient} from './kindeServerClient'; | ||
|
||
export const getFlagFactory = | ||
(req, res) => async (code, defaultValue, flagType) => { | ||
try { | ||
const flag = await kindeClient.getFlag( | ||
sessionManager(req, res), | ||
code, | ||
defaultValue, | ||
flagType | ||
); | ||
|
||
return flag; | ||
} catch (error) { | ||
if (error.message.includes('no default value has been provided')) { | ||
throw error; | ||
} | ||
return {value: defaultValue}; | ||
} | ||
}; |
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,12 @@ | ||
import {getFlagFactory} from './getFlag'; | ||
|
||
export const getIntegerFlagFactory = | ||
(req, res) => async (code, defaultValue) => { | ||
try { | ||
const flag = await getFlagFactory(req, res)(code, defaultValue, 'i'); | ||
return flag.value; | ||
} catch (err) { | ||
console.error(err); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {sessionManager} from './sessionManager'; | ||
import {kindeClient} from './kindeServerClient'; | ||
|
||
export const getOrganizationFactory = (req, res) => async () => { | ||
try { | ||
const organization = await kindeClient.getOrganization( | ||
sessionManager(req, res) | ||
); | ||
return organization; | ||
} catch (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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {sessionManager} from './sessionManager'; | ||
import {kindeClient} from './kindeServerClient'; | ||
|
||
export const getPermissionFactory = (req, res) => async (name) => { | ||
try { | ||
const permission = await kindeClient.getPermission( | ||
sessionManager(req, res), | ||
name | ||
); | ||
return permission; | ||
} catch (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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {sessionManager} from './sessionManager'; | ||
import {kindeClient} from './kindeServerClient'; | ||
|
||
export const getPermissionsFactory = (req, res) => async () => { | ||
try { | ||
const permissions = await kindeClient.getPermissions( | ||
sessionManager(req, res) | ||
); | ||
return permissions; | ||
} catch (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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {getFlagFactory} from './getFlag'; | ||
|
||
export const getStringFlagFactory = | ||
(req, res) => async (code, defaultValue) => { | ||
try { | ||
const flag = await getFlagFactory(req, res)(code, defaultValue, 's'); | ||
return flag.value; | ||
} catch (err) { | ||
console.error(err); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {sessionManager} from './sessionManager'; | ||
import {kindeClient} from './kindeServerClient'; | ||
|
||
export const getUserFactory = (req, res) => async () => { | ||
try { | ||
const user = await kindeClient.getUser(sessionManager(req, res)); | ||
return user; | ||
} catch (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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {sessionManager} from './sessionManager'; | ||
import {kindeClient} from './kindeServerClient'; | ||
|
||
export const getUserOrganizationsFactory = (req, res) => async () => { | ||
try { | ||
const userOrgs = await kindeClient.getUserOrganizations( | ||
sessionManager(req, res) | ||
); | ||
return userOrgs; | ||
} catch (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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {getAccessTokenFactory} from './getAccessToken'; | ||
import {getBooleanFlagFactory} from './getBooleanFlag'; | ||
import {getFlagFactory} from './getFlag'; | ||
import {getIntegerFlagFactory} from './getIntegerFlag'; | ||
import {getOrganizationFactory} from './getOrganization'; | ||
import {getPermissionFactory} from './getPermission'; | ||
import {getPermissionsFactory} from './getPermissions'; | ||
import {getStringFlagFactory} from './getStringFlag'; | ||
import {getUserFactory} from './getUser'; | ||
import {getUserOrganizationsFactory} from './getUserOrganizations'; | ||
import {isAuthenticatedFactory} from './isAuthenticated'; | ||
|
||
export const getKindeServerSession = (req, res) => ({ | ||
getAccessToken: getAccessTokenFactory(req, res), | ||
getBooleanFlag: getBooleanFlagFactory(req, res), | ||
getFlag: getFlagFactory(req, res), | ||
getIntegerFlag: getIntegerFlagFactory(req, res), | ||
getOrganization: getOrganizationFactory(req, res), | ||
getPermission: getPermissionFactory(req, res), | ||
getPermissions: getPermissionsFactory(req, res), | ||
getStringFlag: getStringFlagFactory(req, res), | ||
getUser: getUserFactory(req, res), | ||
getUserOrganizations: getUserOrganizationsFactory(req, res), | ||
isAuthenticated: isAuthenticatedFactory(req, res) | ||
}); |
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,6 @@ | ||
import {getUserFactory} from './getUser'; | ||
|
||
export const isAuthenticatedFactory = (req, res) => async () => { | ||
const user = await getUserFactory(req, res)(); | ||
return Boolean(user); | ||
}; |
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,7 @@ | ||
import {createKindeServerClient} from '@kinde-oss/kinde-typescript-sdk'; | ||
import {config} from '../config/index'; | ||
|
||
export const kindeClient = createKindeServerClient( | ||
config.grantType, | ||
config.clientOptions | ||
); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.