-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
27 changed files
with
8,189 additions
and
81 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
dist | ||
node_modules | ||
.nuxt |
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,4 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ['@nuxt/eslint-config', 'prettier'], | ||
} |
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,3 @@ | ||
dist | ||
node_modules | ||
.nuxt |
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 @@ | ||
module.exports = { | ||
semi: false, | ||
trailingComma: 'es5', | ||
singleQuote: true, | ||
printWidth: 120, | ||
} |
Empty file.
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,20 @@ | ||
Copyright (c) 2012-2023 Scott Chacon and others | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,94 +1,119 @@ | ||
<!-- | ||
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 | ||
# Nuxt Logto | ||
|
||
[![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. | ||
Logto auth module for Nuxt 3. | ||
|
||
- [✨ Release Notes](/CHANGELOG.md) | ||
<!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/my-module?file=playground%2Fapp.vue) --> | ||
<!-- - [📖 Documentation](https://example.com) --> | ||
|
||
## Features | ||
|
||
<!-- Highlight some of the features your module provide here --> | ||
- ⛰ Foo | ||
- 🚠 Bar | ||
- 🌲 Baz | ||
|
||
## Quick Setup | ||
|
||
1. Add `my-module` dependency to your project | ||
1. Add `@zernico/nuxt-logto` dependency to your project | ||
|
||
```bash | ||
# Using pnpm | ||
pnpm add -D my-module | ||
pnpm add -D @zernico/nuxt-logto | ||
|
||
# Using yarn | ||
yarn add --dev my-module | ||
yarn add --dev @zernico/nuxt-logto | ||
|
||
# Using npm | ||
npm install --save-dev my-module | ||
npm install --save-dev @zernico/nuxt-logto | ||
``` | ||
|
||
2. Add `@zernico/nuxt-logto` to the `modules` section of `nuxt.config.ts` | ||
|
||
```js | ||
export default defineNuxtConfig({ | ||
modules: ['@zernico/nuxt-logto'], | ||
}) | ||
``` | ||
|
||
2. Add `my-module` to the `modules` section of `nuxt.config.ts` | ||
3. Configure it: | ||
|
||
```js | ||
export default defineNuxtConfig({ | ||
modules: [ | ||
'my-module' | ||
] | ||
modules: ['@zernico/nuxt-logto'], | ||
logto: { | ||
appId: '<your-application-id>', | ||
appSecret: '<your-app-secret-copied-from-console>', | ||
endpoint: '<your-logto-endpoint>', // E.g. http://localhost:3001 | ||
baseUrl: '<your-nextjs-app-base-url>', // E.g. http://localhost:3000 | ||
cookieSecret: 'complex_password_at_least_32_characters_long', | ||
cookieSecure: process.env.NODE_ENV === 'production', | ||
cookieHttpOnly: true, | ||
resources: ['<your-resource-id>'], // optionally add a resource | ||
}, | ||
}) | ||
``` | ||
|
||
That's it! You can now use My Module in your Nuxt app ✨ | ||
4. Add the api routes | ||
|
||
```js | ||
// lib/logto.ts | ||
import LogtoClient from '@logto/next' | ||
|
||
export const logtoClient = new LogtoClient() | ||
``` | ||
|
||
```js | ||
// server/api/logto/[action].ts | ||
import { logtoClient } from '~/lib/logto' | ||
|
||
export default logtoClient.handleAuthRoutes() | ||
``` | ||
|
||
5. Optional configuration | ||
|
||
```js | ||
// server/api/logto/[action].ts | ||
import { logtoClient } from '~/lib/logto' | ||
|
||
export default logtoClient.handleAuthRoutes({ | ||
getAccessToken: true, // get access token from logto | ||
resource: '<your-resource-id>', // optionally add a resource to audience of access token | ||
fetchUserInfo: true, // fetch user info from logto, in most cases you want to use claims instead | ||
}) | ||
``` | ||
|
||
That's it! You can now use Nuxt Logto in your Nuxt app ✨ | ||
|
||
## Development | ||
|
||
```bash | ||
# Install dependencies | ||
npm install | ||
pnpm install | ||
|
||
# Generate type stubs | ||
npm run dev:prepare | ||
pnpm run dev:prepare | ||
|
||
# Develop with the playground | ||
npm run dev | ||
pnpm run dev | ||
|
||
# Build the playground | ||
npm run dev:build | ||
pnpm run dev:build | ||
|
||
# Run ESLint | ||
npm run lint | ||
pnpm run lint | ||
|
||
# Run Vitest | ||
npm run test | ||
npm run test:watch | ||
pnpm run test | ||
pnpm 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 | ||
|
||
[npm-version-src]: https://img.shields.io/npm/v/@zernico/nuxt-logto/latest.svg?style=flat&colorA=18181B&colorB=28CF8D | ||
[npm-version-href]: https://npmjs.com/package/@zernico/nuxt-logto | ||
[npm-downloads-src]: https://img.shields.io/npm/dm/@zernico/nuxt-logto.svg?style=flat&colorA=18181B&colorB=28CF8D | ||
[npm-downloads-href]: https://npmjs.com/package/@zernico/nuxt-logto | ||
[license-src]: https://img.shields.io/npm/l/@zernico/nuxt-logto.svg?style=flat&colorA=18181B&colorB=28CF8D | ||
[license-href]: https://npmjs.com/package/@zernico/nuxt-logto | ||
[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js | ||
[nuxt-href]: https://nuxt.com |
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,8 +1,19 @@ | ||
<script setup> | ||
import { useLogto } from './.nuxt/imports' | ||
const { claims, accessToken, signIn, signOut, signUp, refresh } = useLogto() | ||
</script> | ||
|
||
<template> | ||
<div> | ||
Nuxt module playground! | ||
{{ JSON.stringify(claims) }} | ||
|
||
{{ JSON.stringify(accessToken) }} | ||
|
||
<button @click="() => signIn()">Sign In</button> | ||
<button @click="() => signUp()">Sign Up</button> | ||
<button @click="() => signOut()">Sign Out</button> | ||
<button @click="() => refresh()">Refresh</button> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
</script> |
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,3 @@ | ||
import { LogtoClient } from '#logto' | ||
|
||
export const logtoClient = new LogtoClient() |
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,4 +1,14 @@ | ||
export default defineNuxtConfig({ | ||
modules: ['../src/module'], | ||
myModule: {} | ||
ssr: true, | ||
logto: { | ||
appId: '<your-application-id>', | ||
appSecret: '<your-app-secret-copied-from-console>', | ||
endpoint: '<your-logto-endpoint>', // E.g. http://localhost:3001 | ||
baseUrl: '<your-nextjs-app-base-url>', // E.g. http://localhost:3000 | ||
cookieSecret: 'complex_password_at_least_32_characters_long', | ||
cookieSecure: process.env.NODE_ENV === 'production', | ||
cookieHttpOnly: true, | ||
resources: ['<your-resource-id>'], // optionally add a resource | ||
}, | ||
}) |
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,4 +1,4 @@ | ||
{ | ||
"private": true, | ||
"name": "my-module-playground" | ||
"name": "nuxt-logto-playground" | ||
} |
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 { logtoClient } from '~/lib/logto' | ||
|
||
export default logtoClient.handleAuthRoutes({ | ||
getAccessToken: true, | ||
resource: '<your-resource-id>', | ||
}) |
Oops, something went wrong.