Skip to content

Commit

Permalink
chore: enable type testing step
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Mar 5, 2024
1 parent 0d81972 commit 2ea4217
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
- name: 🚧 Set up project
run: pnpm dev:prepare

- name: 💪 Test types
run: pnpm test:types

- name: 🛠 Build project
run: pnpm prepack

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"release": "pnpm lint && pnpm test && pnpm prepack && changelogen --release && npm publish && git push --follow-tags",
"lint": "eslint .",
"test": "vitest run",
"test:watch": "vitest watch"
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
},
"dependencies": {
"@kinde-oss/kinde-typescript-sdk": "^2.6.2",
Expand All @@ -44,7 +44,9 @@
"eslint": "8.57.0",
"happy-dom": "^13.6.2",
"nuxt": "3.10.3",
"vitest": "1.3.1"
"typescript": "^5.3.3",
"vitest": "1.3.1",
"vue-tsc": "^2.0.4"
},
"resolutions": {
"@nuxt/schema": "3.10.3",
Expand Down
102 changes: 93 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/runtime/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import type { AuthState } from './types'
export default defineNuxtPlugin(async () => {
const state = useState<AuthState>('auth', shallowRef)
if (import.meta.server) {
const event = useRequestEvent()
const isLoggedIn = await event.context.kinde.isAuthenticated()
const kinde = useRequestEvent()!.context.kinde
const isLoggedIn = await kinde.isAuthenticated()
state.value = isLoggedIn
? { loggedIn: true, user: await event.context.kinde.getUserProfile() }
? { loggedIn: true, user: await kinde.getUserProfile() }
: { loggedIn: false, user: null }
}

Expand Down
11 changes: 5 additions & 6 deletions src/runtime/server/middleware/kinde.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { getSession, updateSession, clearSession } from '#imports'

export default defineEventHandler(async event => {
const sessionManager = await createSessionManager(event)
event.context.kinde = { sessionManager }
const kindeContext = { sessionManager } as Record<string, any>
const kindeClient = getKindeClient()
for (const key in kindeClient) {
event.context.kinde[key] = kindeClient[key].bind(
kindeClient,
sessionManager
)
for (const _key in kindeClient) {
const key = _key as keyof typeof kindeClient
kindeContext[key] = (kindeClient[key] as any).bind(kindeClient, sessionManager)
}
event.context.kinde = kindeContext as any
})

async function createSessionManager(event: H3Event): Promise<SessionManager> {
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../.nuxt/tsconfig.server.json"
}
8 changes: 7 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"extends": "./.nuxt/tsconfig.json"
"extends": "./.nuxt/tsconfig.json",
"exclude": [
"dist",
"node_modules",
"playground",
"src/runtime/server"
]
}

0 comments on commit 2ea4217

Please sign in to comment.