Skip to content
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

Peter/backwards compatibilty get token #77

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You can also use the NextJS starter kit [here](https://github.com/kinde-starter

## Documentation

Please refer to the Kinde [NextJS SDK document](https://kinde.com/docs/developer-tools/nextjs-sdk).
Please refer to the Kinde [NextJS SDK document](https://kinde.notion.site/Next-js-App-Router-v2-e7a16d8ae38e45b6ad052910075e24ef?pvs=4).

## Publishing

Expand Down
2 changes: 2 additions & 0 deletions src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ const initialState = {
accessToken: null,
getClaim: null,
getFlag: null,
getToken: null,
getBooleanFlag: null,
getStringFlag: null,
getIntegerFlag: null,
getPermission: null,
getPermissions: null,
permissions: null,
organization: null,
userOrganizations: null
Expand Down
14 changes: 12 additions & 2 deletions src/frontend/AuthProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ const handleError = () => {
* @return {AccessToken}
*/

/**
* @callback getToken
* @return {string | null}
*/

/**
* @callback getIdToken
* @return {IdToken}
Expand Down Expand Up @@ -144,6 +149,7 @@ const handleError = () => {
* @property {getPermission} getPermission
* @property {getStringFlag} getStringFlag
* @property {getAccessToken} getAccessToken
* @property {getToken} getToken
* @property {getPermissions} getPermissions
* @property {getOrganization} getOrganization
* @property {getUserOrganzations} getUserOrganzations
Expand Down Expand Up @@ -197,8 +203,7 @@ const tokenFetcher = async (url) => {
*/
export const KindeProvider = ({children}) => {
const [state, setState] = useState({
...config.initialState,
getToken: () => null
...config.initialState
});

const setupUrl = `${config.apiPath}/setup`;
Expand All @@ -215,9 +220,11 @@ export const KindeProvider = ({children}) => {
userOrganizations,
featureFlags,
accessToken,
accessTokenEncoded,
idToken
} = tokens;

const getToken = () => accessTokenEncoded;
const getAccessToken = () => accessToken;
const getIdToken = () => idToken;
const getPermissions = () => permissions;
Expand Down Expand Up @@ -298,6 +305,7 @@ export const KindeProvider = ({children}) => {
organization,
userOrganizations,
getAccessToken,
getToken,
getClaim,
getFlag,
getIdToken,
Expand Down Expand Up @@ -335,6 +343,7 @@ export const KindeProvider = ({children}) => {
accessToken,
idToken,
getAccessToken,
getToken,
getClaim,
getFlag,
getIdToken,
Expand All @@ -360,6 +369,7 @@ export const KindeProvider = ({children}) => {
accessToken,
idToken,
getAccessToken,
getToken,
getClaim,
getFlag,
getIdToken,
Expand Down
5 changes: 5 additions & 0 deletions src/frontend/KindeBrowserClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {flagDataTypeMap} from './AuthProvider.jsx';
export const useKindeBrowserClient = () => {
const [state, setState] = useState({
accessToken: null,
accessTokenEncoded: null,
error: null,
featureFlags: [],
idToken: null,
Expand Down Expand Up @@ -96,6 +97,9 @@ export const useKindeBrowserClient = () => {
const getAccessToken = () => {
return state.accessToken;
};
const getToken = () => {
return state.accessTokenEncoded;
};
const getIdToken = () => {
return state.idToken;
};
Expand Down Expand Up @@ -124,6 +128,7 @@ export const useKindeBrowserClient = () => {
getStringFlag,
getClaim,
getAccessToken,
getToken,
getIdToken,
getOrganization,
getPermissions,
Expand Down
5 changes: 5 additions & 0 deletions src/handlers/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export const setup = async (routerClient) => {
'id_token_payload'
);

const accessTokenEncoded = await routerClient.sessionManager.getSessionItem(
'access_token'
);

const permissions = await routerClient.kindeClient.getClaimValue(
routerClient.sessionManager,
'permissions'
Expand All @@ -32,6 +36,7 @@ export const setup = async (routerClient) => {

return routerClient.json({
accessToken,
accessTokenEncoded,
idToken,
user,
permissions,
Expand Down
Loading