-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add helper methods and support nuxt
- Loading branch information
1 parent
d37eaf8
commit 6a2df5d
Showing
11 changed files
with
802 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"git": { | ||
"requireBranch": "main", | ||
"commitMessage": "chore: release v${version}" | ||
}, | ||
"hooks": { | ||
"before:init": ["git pull", "pnpm run lint"], | ||
"after:bump": "npx auto-changelog -p && npm run build" | ||
}, | ||
"github": { | ||
"release": true | ||
}, | ||
"npm": { | ||
"publish": true | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export const TOKEN_ENDPOINT = `${process.env.KINDE_DOMAIN}/oauth2/token`; | ||
|
||
export const DEFAULT_TOKEN_SCOPES: string = "openid profile email offline"; | ||
export const DEFAULT_TOKEN_SCOPES: string = ""; |
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 |
---|---|---|
@@ -1,38 +1,9 @@ | ||
import * as dotenv from "dotenv"; | ||
import { init } from "./config"; | ||
dotenv.config(); | ||
|
||
init(); | ||
|
||
export * from "./api/index"; | ||
export * from "./utilities/index"; | ||
|
||
import { OpenAPI } from "./api/index"; | ||
import { kindeConfig } from "./config"; | ||
import { getToken } from "./utilities/getToken"; | ||
|
||
if (!process.env.KINDE_DOMAIN) { | ||
throw new Error("KINDE_DOMAIN is not set"); | ||
} | ||
|
||
if (!process.env.KINDE_CLIENT_SECRET) { | ||
throw new Error("KINDE_CLIENT_SECRET is not set"); | ||
} | ||
|
||
if (!process.env.KINDE_CLIENT_ID) { | ||
throw new Error("KINDE_CLIENT_ID is not set"); | ||
} | ||
|
||
if (!process.env.KINDE_DOMAIN) { | ||
throw new Error("KINDE_DOMAIN is not set"); | ||
} | ||
|
||
kindeConfig.clientId = process.env.KINDE_CLIENT_ID; | ||
kindeConfig.clientSecret = process.env.KINDE_CLIENT_SECRET; | ||
kindeConfig.audience = process.env.KINDE_CLIENT_SECRET; | ||
OpenAPI.BASE = process.env.KINDE_DOMAIN; | ||
|
||
async function main() { | ||
OpenAPI.TOKEN = async () => { | ||
return await getToken(); | ||
}; | ||
} | ||
|
||
main(); | ||
export { init } from "./config"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { type JWTDecoded, jwtDecode } from "../jwt-decode"; | ||
/** | ||
* Checks if the given audience is present in the token | ||
* @param token - JWT to be checked, can be a string or a decoded JWT token | ||
* @returns - True if the audience is present in the token, false otherwise | ||
*/ | ||
export const checkAudience = ( | ||
token?: string | JWTDecoded, | ||
audience?: string, | ||
): boolean => { | ||
if (!audience) { | ||
return false; | ||
} | ||
const decoded = typeof token === "string" ? jwtDecode(token) : token; | ||
if (!decoded) { | ||
return false; | ||
} | ||
return decoded.aud.includes(audience); | ||
}; |
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 { type JWTDecoded, jwtDecode } from "../jwt-decode"; | ||
/** | ||
* Checks if the given audience is present in the token | ||
* @param token - JWT to be checked, can be a string or a decoded JWT token | ||
* @returns - True if the audience is present in the token, false otherwise | ||
*/ | ||
export const hasTokenExpired = (token?: string | JWTDecoded): boolean => { | ||
const decoded = typeof token === "string" ? jwtDecode(token) : token; | ||
if (!decoded) { | ||
return false; | ||
} | ||
return !!decoded.exp && decoded.exp * 1000 > Date.now(); | ||
}; |
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 { jwtDecode } from "./jwt-decode"; | ||
|
||
export const decodeWebhook = (token: string): any => { | ||
const decoded = jwtDecode(token); | ||
return decoded; | ||
}; |
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
Oops, something went wrong.