Skip to content

Commit bb82a5f

Browse files
authored
Merge pull request #642 from sachigoyal/sachi/fix-echo-provider-authjs
fix: updated token endpoint auth method to make it work with auth.js
2 parents eec3f55 + 12f6e55 commit bb82a5f

29 files changed

Lines changed: 5150 additions & 4 deletions

File tree

.github/workflows/publish-sdks.yml

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
next-published: ${{ steps.publish-next.outputs.published }}
2323
aix402-published: ${{ steps.publish-aix402.outputs.published }}
2424
echo-start-published: ${{ steps.publish-echo-start.outputs.published }}
25+
authjs-provider-published: ${{ steps.publish-authjs-provider.outputs.published }}
2526
version: ${{ steps.get-version.outputs.version }}
2627

2728
steps:
@@ -273,11 +274,55 @@ jobs:
273274
echo "✅ Successfully published $PACKAGE_NAME"
274275
fi
275276
277+
# Auth.js Provider
278+
- name: Build Auth.js Provider
279+
working-directory: ./packages/sdk/auth-js-provider
280+
run: |
281+
echo "🔨 Building Auth.js Provider..."
282+
pnpm run build
283+
echo "✅ Auth.js Provider built"
284+
285+
- name: Test Auth.js Provider
286+
working-directory: ./packages/sdk/auth-js-provider
287+
run: |
288+
echo "🧪 Testing Auth.js Provider..."
289+
pnpm run test
290+
pnpm run type-check
291+
echo "✅ Auth.js Provider tests passed"
292+
293+
- name: Check and publish Auth.js Provider
294+
id: publish-authjs-provider
295+
working-directory: ./packages/sdk/auth-js-provider
296+
env:
297+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
298+
run: |
299+
PACKAGE_NAME=$(node -p "require('./package.json').name")
300+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
301+
FORCE_PUBLISH="${{ github.event.inputs.force_publish }}"
302+
303+
if npm view "$PACKAGE_NAME@$PACKAGE_VERSION" version 2>/dev/null; then
304+
if [ "$FORCE_PUBLISH" = "true" ]; then
305+
echo "⚠️ Version $PACKAGE_VERSION of $PACKAGE_NAME already exists on npm, but force_publish is enabled"
306+
echo "🚀 Publishing $PACKAGE_NAME to npm..."
307+
pnpm publish --access public --no-git-checks
308+
echo "published=true" >> $GITHUB_OUTPUT
309+
echo "✅ Successfully published $PACKAGE_NAME"
310+
else
311+
echo "❌ Version $PACKAGE_VERSION of $PACKAGE_NAME already exists on npm - skipping"
312+
echo "published=false" >> $GITHUB_OUTPUT
313+
fi
314+
else
315+
echo "🚀 Publishing $PACKAGE_NAME to npm..."
316+
pnpm publish --access public --no-git-checks
317+
echo "published=true" >> $GITHUB_OUTPUT
318+
echo "✅ Successfully published $PACKAGE_NAME"
319+
fi
320+
276321
create-tag:
277322
name: Create version tag
278323
runs-on: ubuntu-latest
279324
needs: publish
280-
if: (needs.publish.outputs.typescript-published == 'true' || needs.publish.outputs.react-published == 'true' || needs.publish.outputs.next-published == 'true' || needs.publish.outputs.aix402-published == 'true' || needs.publish.outputs.echo-start-published == 'true') && github.ref == 'refs/heads/production' && !startsWith(github.ref, 'refs/tags/')
325+
if: (needs.publish.outputs.typescript-published == 'true' || needs.publish.outputs.react-published == 'true' || needs.publish.outputs.next-published == 'true' || needs.publish.outputs.aix402-published == 'true' || needs.publish.outputs.echo-start-published == 'true' || needs.publish.outputs.authjs-provider-published == 'true') && github.ref == 'refs/heads/production' && !startsWith(github.ref, 'refs/tags/')
281326

282327
steps:
283328
- name: Checkout code
@@ -340,6 +385,7 @@ jobs:
340385
- \`@merit-systems/echo-next-sdk\`
341386
- \`@merit-systems/ai-x402\`
342387
- \`echo-start\` (CLI tool)
388+
- \`@merit-systems/echo-authjs-provider\`
343389
344390
### Installation
345391
\`\`\`bash
@@ -348,6 +394,7 @@ jobs:
348394
npm install @merit-systems/echo-next-sdk
349395
npm install @merit-systems/ai-x402
350396
npm install -g echo-start
397+
npm install @merit-systems/echo-authjs-provider
351398
\`\`\`
352399
353400
This tag was automatically created after successful npm publishing from the production branch.

.github/workflows/test-publish.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
- 'packages/sdk/next/**'
1010
- 'packages/sdk/aix402/**'
1111
- 'packages/sdk/echo-start/**'
12+
- 'packages/sdk/auth-js-provider/**'
1213
- '.github/workflows/publish-sdks.yml'
1314
- '.github/workflows/test-publish.yml'
1415
- 'pnpm-lock.yaml'
@@ -20,6 +21,7 @@ on:
2021
- 'packages/sdk/next/**'
2122
- 'packages/sdk/aix402/**'
2223
- 'packages/sdk/echo-start/**'
24+
- 'packages/sdk/auth-js-provider/**'
2325
- '.github/workflows/publish-sdks.yml'
2426
- '.github/workflows/test-publish.yml'
2527

@@ -33,11 +35,13 @@ jobs:
3335
next-ready: ${{ steps.test-next.outputs.ready }}
3436
aix402-ready: ${{ steps.test-aix402.outputs.ready }}
3537
echo-start-ready: ${{ steps.test-echo-start.outputs.ready }}
38+
authjs-provider-ready: ${{ steps.test-authjs-provider.outputs.ready }}
3639
typescript-version: ${{ steps.get-versions.outputs.typescript-version }}
3740
react-version: ${{ steps.get-versions.outputs.react-version }}
3841
next-version: ${{ steps.get-versions.outputs.next-version }}
3942
aix402-version: ${{ steps.get-versions.outputs.aix402-version }}
4043
echo-start-version: ${{ steps.get-versions.outputs.echo-start-version }}
44+
authjs-provider-version: ${{ steps.get-versions.outputs.authjs-provider-version }}
4145

4246
env:
4347
# Database Configuration
@@ -110,16 +114,19 @@ jobs:
110114
NEXT_VERSION=$(node -p "require('./packages/sdk/next/package.json').version")
111115
AIX402_VERSION=$(node -p "require('./packages/sdk/aix402/package.json').version")
112116
ECHO_START_VERSION=$(node -p "require('./packages/sdk/echo-start/package.json').version")
117+
AUTHJS_PROVIDER_VERSION=$(node -p "require('./packages/sdk/auth-js-provider/package.json').version")
113118
echo "typescript-version=$TS_VERSION" >> $GITHUB_OUTPUT
114119
echo "react-version=$REACT_VERSION" >> $GITHUB_OUTPUT
115120
echo "next-version=$NEXT_VERSION" >> $GITHUB_OUTPUT
116121
echo "aix402-version=$AIX402_VERSION" >> $GITHUB_OUTPUT
117122
echo "echo-start-version=$ECHO_START_VERSION" >> $GITHUB_OUTPUT
123+
echo "authjs-provider-version=$AUTHJS_PROVIDER_VERSION" >> $GITHUB_OUTPUT
118124
echo "📦 TypeScript SDK: v$TS_VERSION"
119125
echo "📦 React SDK: v$REACT_VERSION"
120126
echo "📦 Next.js SDK: v$NEXT_VERSION"
121127
echo "📦 AIx402 SDK: v$AIX402_VERSION"
122128
echo "📦 Echo Start CLI: v$ECHO_START_VERSION"
129+
echo "📦 Auth.js Provider: v$AUTHJS_PROVIDER_VERSION"
123130
124131
# TypeScript SDK Tests
125132
- name: Check TypeScript SDK configuration
@@ -461,3 +468,71 @@ jobs:
461468
462469
echo "ready=true" >> $GITHUB_OUTPUT
463470
echo "✅ Echo Start CLI is ready for publishing"
471+
472+
# Auth.js Provider Tests
473+
- name: Check Auth.js Provider configuration
474+
working-directory: ./packages/sdk/auth-js-provider
475+
run: |
476+
echo "🔍 Checking Auth.js Provider configuration..."
477+
PACKAGE_NAME=$(node -p "require('./package.json').name")
478+
echo "Name: $PACKAGE_NAME"
479+
480+
# Check if package.json has required fields for publishing
481+
if [ "$(node -p "require('./package.json').private || false")" = "true" ]; then
482+
echo "❌ Package is marked as private - cannot publish"
483+
exit 1
484+
fi
485+
486+
if [ -z "$PACKAGE_NAME" ]; then
487+
echo "❌ Package name is missing"
488+
exit 1
489+
fi
490+
491+
echo "✅ Auth.js Provider configuration looks good"
492+
493+
- name: Build and test Auth.js Provider
494+
id: test-authjs-provider
495+
working-directory: ./packages/sdk/auth-js-provider
496+
run: |
497+
echo "🔨 Building Auth.js Provider..."
498+
pnpm run build
499+
500+
echo "🧪 Testing Auth.js Provider..."
501+
pnpm run test
502+
pnpm run type-check
503+
504+
echo "📁 Checking build output..."
505+
if [ ! -d "dist" ]; then
506+
echo "❌ dist directory not found"
507+
exit 1
508+
fi
509+
510+
# Check for main files
511+
MAIN_FILE=$(node -p "require('./package.json').main")
512+
TYPES_FILE=$(node -p "require('./package.json').types")
513+
514+
if [ ! -z "$MAIN_FILE" ] && [ ! -f "$MAIN_FILE" ]; then
515+
echo "❌ Main file not found: $MAIN_FILE"
516+
exit 1
517+
fi
518+
519+
if [ ! -z "$TYPES_FILE" ] && [ ! -f "$TYPES_FILE" ]; then
520+
echo "❌ Types file not found: $TYPES_FILE"
521+
exit 1
522+
fi
523+
524+
echo "📏 Checking dist size..."
525+
du -sh dist || true
526+
527+
echo "🔍 Simulating version check..."
528+
PACKAGE_NAME=$(node -p "require('./package.json').name")
529+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
530+
531+
if npm view "$PACKAGE_NAME@$PACKAGE_VERSION" version 2>/dev/null; then
532+
echo "⚠️ Version $PACKAGE_VERSION already exists on npm"
533+
else
534+
echo "✅ Version $PACKAGE_VERSION does not exist - would be published"
535+
fi
536+
537+
echo "ready=true" >> $GITHUB_OUTPUT
538+
echo "✅ Auth.js Provider is ready for publishing"

packages/app/control/docs/getting-started/templates.mdx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,4 +375,45 @@ Client-side image generation for React applications with Echo billing and image
375375
</Tab>
376376
</Tabs>
377377
</Step>
378+
</Steps>
379+
380+
## Auth.js (NextAuth)
381+
382+
Next.js application demonstrating Echo as an Auth.js provider for authentication.
383+
384+
[View on GitHub](https://github.com/Merit-Systems/echo/tree/master/templates/authjs)
385+
386+
<Steps>
387+
<Step>
388+
### Create an Echo App
389+
Go to [echo.merit.systems/new](https://echo.merit.systems/new) to get an `app_id`.
390+
</Step>
391+
392+
<Step>
393+
### Create an Auth.js app
394+
Run the following commands to create a new app with Auth.js integration.
395+
396+
<Tabs items={['npm', 'yarn', 'pnpm', 'bun']}>
397+
<Tab value="npm">
398+
```sh lineNumbers
399+
npx echo-start@latest --template authjs --app-id YOUR_ECHO_APP_ID
400+
```
401+
</Tab>
402+
<Tab value="yarn">
403+
```sh lineNumbers
404+
yarn dlx echo-start@latest --template authjs --app-id YOUR_ECHO_APP_ID
405+
```
406+
</Tab>
407+
<Tab value="pnpm">
408+
```sh lineNumbers
409+
pnpx echo-start@latest --template authjs --app-id YOUR_ECHO_APP_ID
410+
```
411+
</Tab>
412+
<Tab value="bun">
413+
```sh lineNumbers
414+
bunx echo-start@latest --template authjs --app-id YOUR_ECHO_APP_ID
415+
```
416+
</Tab>
417+
</Tabs>
418+
</Step>
378419
</Steps>

packages/app/control/docs/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ We provide a variety of ready-to-use templates to help you get started quickly w
126126
- **Next.js Image Generation** — Image generation app with Echo billing
127127
- **Next.js Video** — Video generation app with Echo integration
128128
- **Next.js API Key** — Server-side API key management template
129+
- **Auth.js (NextAuth)** — Next.js app with Echo as an Auth.js provider
129130
- **React Chat** — Chat interface for React apps
130131
- **React Image** — Image generation for React apps
131132

packages/sdk/auth-js-provider/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "@merit/echo-authjs-provider",
3-
"version": "1.0.1",
2+
"name": "@merit-systems/echo-authjs-provider",
3+
"version": "0.0.1",
44
"description": "Auth.js provider for Echo login",
55
"type": "module",
66
"main": "./dist/index.js",

packages/sdk/auth-js-provider/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function validateAppId(appId: string, context?: string): void {
5252
* const response = await Auth(request, {
5353
* providers: [
5454
* Echo({
55-
* clientId: ECHO_CLIENT_ID,
55+
* appId: ECHO_APP_ID,
5656
* }),
5757
* ],
5858
* })
@@ -96,6 +96,9 @@ export default function Echo(
9696
image: profile.picture || null,
9797
};
9898
},
99+
client: {
100+
token_endpoint_auth_method: 'none',
101+
},
99102
options: config,
100103
};
101104
}

packages/sdk/echo-start/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ const DEFAULT_TEMPLATES = {
6868
description:
6969
'Vite React application with Echo and the Vercel AI SDK for image generation',
7070
},
71+
authjs: {
72+
title: 'Auth.js (NextAuth)',
73+
description:
74+
'Next.js application with Echo as an Auth.js provider for authentication',
75+
},
7176
} as const;
7277

7378
type TemplateName = keyof typeof DEFAULT_TEMPLATES;

templates/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,22 @@ npx echo-start@latest --template react-image
174174

175175
---
176176

177+
#### Auth.js (NextAuth) (`authjs`)
178+
179+
Next.js application demonstrating Echo as an Auth.js provider for authentication.
180+
181+
```bash
182+
npx echo-start@latest --template authjs
183+
```
184+
185+
**Features:**
186+
187+
- Auth.js (NextAuth v5) integration
188+
- Echo as authentication provider
189+
- Server-side session management
190+
191+
---
192+
177193
## Template Structure
178194

179195
Each template follows a consistent structure:

templates/authjs/.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
AUTH_SECRET=
2+
3+
# get from: https://echo.merit.systems
4+
ECHO_APP_ID=
5+
NEXT_PUBLIC_ECHO_APP_ID=

templates/authjs/.env.local

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
AUTH_SECRET=
2+
ECHO_APP_ID="74d9c979-e036-4e43-904f-32d214b361fc"
3+
NEXT_PUBLIC_ECHO_APP_ID="74d9c979-e036-4e43-904f-32d214b361fc"

0 commit comments

Comments
 (0)