Skip to content

Commit

Permalink
chore: init
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Sep 6, 2023
0 parents commit 54b4163
Show file tree
Hide file tree
Showing 26 changed files with 8,095 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
@@ -0,0 +1,12 @@
root = true

[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .eslintignore
@@ -0,0 +1,2 @@
dist
node_modules
4 changes: 4 additions & 0 deletions .eslintrc
@@ -0,0 +1,4 @@
{
"root": true,
"extends": ["@nuxt/eslint-config"]
}
56 changes: 56 additions & 0 deletions .gitignore
@@ -0,0 +1,56 @@
# Dependencies
node_modules

# Logs
*.log*

# Temp directories
.temp
.tmp
.cache

# Yarn
**/.yarn/cache
**/.yarn/*state*

# Generated dirs
dist

# Nuxt
.nuxt
.output
.data
.vercel_build_output
.build-*
.netlify

# Env
.env

# Testing
reports
coverage
*.lcov
.nyc_output

# VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Intellij idea
*.iml
.idea

# OSX
.DS_Store
.AppleDouble
.LSOverride
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
1 change: 1 addition & 0 deletions .npmrc
@@ -0,0 +1 @@
shamefully-hoist=true
2 changes: 2 additions & 0 deletions .nuxtrc
@@ -0,0 +1,2 @@
# imports.autoImport=false
typescript.includeWorkspace=true
94 changes: 94 additions & 0 deletions README.md
@@ -0,0 +1,94 @@
<!--
Get your module up and running quickly.
Find and replace all on all files (CMD+SHIFT+F):
- Name: My Module
- Package name: my-module
- Description: My new Nuxt module
-->

# My Module

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![License][license-src]][license-href]
[![Nuxt][nuxt-src]][nuxt-href]

My new Nuxt module for doing amazing things.

- [&nbsp;Release Notes](/CHANGELOG.md)
<!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/my-module?file=playground%2Fapp.vue) -->
<!-- - [📖 &nbsp;Documentation](https://example.com) -->

## Features

<!-- Highlight some of the features your module provide here -->
-&nbsp;Foo
- 🚠 &nbsp;Bar
- 🌲 &nbsp;Baz

## Quick Setup

1. Add `my-module` dependency to your project

```bash
# Using pnpm
pnpm add -D my-module

# Using yarn
yarn add --dev my-module

# Using npm
npm install --save-dev my-module
```

2. Add `my-module` to the `modules` section of `nuxt.config.ts`

```js
export default defineNuxtConfig({
modules: [
'my-module'
]
})
```

That's it! You can now use My Module in your Nuxt app ✨

## Development

```bash
# Install dependencies
npm install

# Generate type stubs
npm run dev:prepare

# Develop with the playground
npm run dev

# Build the playground
npm run dev:build

# Run ESLint
npm run lint

# Run Vitest
npm run test
npm run test:watch

# Release new version
npm run release
```

<!-- Badges -->
[npm-version-src]: https://img.shields.io/npm/v/my-module/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-version-href]: https://npmjs.com/package/my-module

[npm-downloads-src]: https://img.shields.io/npm/dm/my-module.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-downloads-href]: https://npmjs.com/package/my-module

[license-src]: https://img.shields.io/npm/l/my-module.svg?style=flat&colorA=18181B&colorB=28CF8D
[license-href]: https://npmjs.com/package/my-module

[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
[nuxt-href]: https://nuxt.com
46 changes: 46 additions & 0 deletions package.json
@@ -0,0 +1,46 @@
{
"name": "my-module",
"version": "1.0.0",
"description": "My new Nuxt module",
"repository": "your-org/my-module",
"license": "MIT",
"type": "module",
"exports": {
".": {
"types": "./dist/types.d.ts",
"import": "./dist/module.mjs",
"require": "./dist/module.cjs"
}
},
"main": "./dist/module.cjs",
"types": "./dist/types.d.ts",
"files": [
"dist"
],
"scripts": {
"prepack": "nuxt-module-build",
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
"lint": "eslint .",
"test": "vitest run",
"test:watch": "vitest watch"
},
"dependencies": {
"@kinde-oss/kinde-typescript-sdk": "^1.0.4",
"@nuxt/kit": "^3.7.1"
},
"devDependencies": {
"@nuxt/devtools": "latest",
"@nuxt/eslint-config": "^0.2.0",
"@nuxt/module-builder": "^0.5.1",
"@nuxt/schema": "^3.7.1",
"@nuxt/test-utils": "^3.7.1",
"@types/node": "^18.17.14",
"changelogen": "^0.5.5",
"eslint": "^8.48.0",
"nuxt": "^3.7.1",
"vitest": "^0.34.3"
}
}
8 changes: 8 additions & 0 deletions playground/app.vue
@@ -0,0 +1,8 @@
<template>
<div>
<NuxtLink href="/api/login" external>Login</NuxtLink>
</div>
</template>

<script setup>
</script>
14 changes: 14 additions & 0 deletions playground/nuxt.config.ts
@@ -0,0 +1,14 @@
export default defineNuxtConfig({
modules: ['../src/module'],
myModule: {},
devtools: { enabled: true },
runtimeConfig: {
kinde: {
authDomain: '',
clientId: '',
clientSecret: '',
redirectURL: '',
logoutRedirectURL: '',
}
}
})
13 changes: 13 additions & 0 deletions playground/package.json
@@ -0,0 +1,13 @@
{
"private": true,
"name": "my-module-playground",
"type": "module",
"scripts": {
"dev": "nuxi dev",
"build": "nuxi build",
"generate": "nuxi generate"
},
"devDependencies": {
"nuxt": "latest"
}
}
4 changes: 4 additions & 0 deletions playground/server/api/login.ts
@@ -0,0 +1,4 @@
export default defineEventHandler(async event => {
const loginURL = await kindeClient.login(event.context.kinde.sessionManager)
await sendRedirect(event, loginURL.href)
})
8 changes: 8 additions & 0 deletions playground/server/api/test.ts
@@ -0,0 +1,8 @@
export default defineEventHandler(async event => {
const loginURL = await kindeClient.login(event.context.kinde.sessionManager)

return {
success: true,
loginURL
}
})
39 changes: 39 additions & 0 deletions playground/server/middleware/session-manager.ts
@@ -0,0 +1,39 @@
import { Session } from "inspector"
import { H3Event } from 'h3'

export default defineEventHandler(async event => {
event.context.kinde = {
sessionManager: await createSessionManager(event)
}
})

interface SessionManager {
getSessionItem: (itemKey: string) => unknown | null;
setSessionItem: (itemKey: string, itemValue: unknown) => void;
removeSessionItem: (itemKey: string) => void;
destroySession: () => void;
}

async function createSessionManager(event: H3Event): Promise<SessionManager> {
const config = { name: 'kinde', password: 'slkdaslkdjfskldafjaslkdjfasldkfjsdf' }
const session = await getSession(event, config)
console.log(session.data)
return {
getSessionItem: (itemKey) => {
return session.data[itemKey]
},
setSessionItem: (itemKey, itemValue) => {
return updateSession(event, config, {
[itemKey]: itemValue
})
},
removeSessionItem: (itemKey) => {
return updateSession(event, config, {
[itemKey]: undefined
})
},
destroySession: () => {
return clearSession(event, config)
},
}
}
4 changes: 4 additions & 0 deletions playground/server/routes/callback.get.ts
@@ -0,0 +1,4 @@
export default defineEventHandler(async event => {
await kindeClient.handleRedirectToApp(event.context.kinde.sessionManager, getRequestURL(event))
await sendRedirect(event, '/')
})
3 changes: 3 additions & 0 deletions playground/server/tsconfig.json
@@ -0,0 +1,3 @@
{
"extends": "../.nuxt/tsconfig.server.json"
}
37 changes: 37 additions & 0 deletions playground/server/utils/kinde.ts
@@ -0,0 +1,37 @@
import {
createKindeServerClient,
GrantType,
type ACClientOptions,
type PKCEClientOptions,
type CCClientOptions,
type ACClient,
type CCClient
} from "@kinde-oss/kinde-typescript-sdk";

const config = useRuntimeConfig()

const clientOptions: ACClientOptions = {
authDomain: config.kinde.authDomain,
clientId: config.kinde.clientId,
clientSecret: config.kinde.clientSecret,
logoutRedirectURL: config.kinde.logoutRedirectURL,
redirectURL: config.kinde.redirectURL
};

//AUTHORIZATION_CODE client
// const kindeClient = createKindeServerClient<ACClient, ACClientOptions>(
// GrantType.AUTHORIZATION_CODE,
// clientOptions
// );

//or PKCE client
export const kindeClient = createKindeServerClient<ACClient, PKCEClientOptions>(
GrantType.PKCE,
clientOptions
);

//or CLIENT_CREDENTIALS client
// const kindeClient = createKindeServerClient<CCClient, CCClientOptions>(
// GrantType.CLIENT_CREDENTIALS,
// clientOptions
// );
3 changes: 3 additions & 0 deletions playground/tsconfig.json
@@ -0,0 +1,3 @@
{
"extends": "./.nuxt/tsconfig.json"
}

0 comments on commit 54b4163

Please sign in to comment.