Skip to content

Commit a97a830

Browse files
authored
test(nuxt, e2e): Create long-running app for Nuxt (clerk#4600)
1 parent 03482f3 commit a97a830

17 files changed

Lines changed: 242 additions & 1 deletion

File tree

.changeset/wet-dryers-pay.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ jobs:
143143
strategy:
144144
fail-fast: false
145145
matrix:
146-
test-name: [ 'generic', 'express', 'quickstart', 'ap-flows', 'elements', 'sessions', 'astro', 'expo-web', 'tanstack-start', 'tanstack-router', 'vue']
146+
test-name: [ 'generic', 'express', 'quickstart', 'ap-flows', 'elements', 'sessions', 'astro', 'expo-web', 'tanstack-start', 'tanstack-router', 'vue', 'nuxt']
147147
test-project: ['chrome']
148148
include:
149149
- test-name: 'nextjs'

integration/presets/longRunningApps.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { envs } from './envs';
66
import { expo } from './expo';
77
import { express } from './express';
88
import { next } from './next';
9+
import { nuxt } from './nuxt';
910
import { react } from './react';
1011
import { remix } from './remix';
1112
import { tanstack } from './tanstack';
@@ -39,6 +40,7 @@ export const createLongRunningApps = () => {
3940
{ id: 'tanstack.start', config: tanstack.start, env: envs.withEmailCodes },
4041
{ id: 'tanstack.router', config: tanstack.router, env: envs.withEmailCodes },
4142
{ id: 'vue.vite', config: vue.vite, env: envs.withCustomRoles },
43+
{ id: 'nuxt.node', config: nuxt.node, env: envs.withCustomRoles },
4244
] as const;
4345

4446
const apps = configs.map(longRunningApplication);

integration/presets/nuxt.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { applicationConfig } from '../models/applicationConfig';
2+
import { templates } from '../templates';
3+
4+
const clerkNuxtLocal = `file:${process.cwd()}/packages/nuxt`;
5+
6+
const nuxtNode = applicationConfig()
7+
.setName('nuxt-node')
8+
.useTemplate(templates['nuxt-node'])
9+
.setEnvFormatter('public', key => `NUXT_PUBLIC_${key}`)
10+
.addScript('setup', 'pnpm install')
11+
.addScript('dev', 'pnpm dev')
12+
.addScript('build', 'pnpm build')
13+
.addScript('serve', 'pnpm preview')
14+
.addDependency('@clerk/nuxt', clerkNuxtLocal);
15+
16+
export const nuxt = {
17+
node: nuxtNode,
18+
} as const;

integration/templates/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const templates = {
1717
'tanstack-start': resolve(__dirname, './tanstack-start'),
1818
'tanstack-router': resolve(__dirname, './tanstack-router'),
1919
'vue-vite': resolve(__dirname, './vue-vite'),
20+
'nuxt-node': resolve(__dirname, './nuxt-node'),
2021
} as const;
2122

2223
if (new Set([...Object.values(templates)]).size !== Object.values(templates).length) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<NuxtPage />
3+
</template>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default defineNuxtRouteMiddleware((to, from) => {
2+
const { userId } = useAuth();
3+
4+
const isPublicPage = ['/sign-in'].includes(to.path);
5+
const isProtectedPage = ['/user'].includes(to.path);
6+
7+
// Is authenticated and trying to access a public page
8+
if (userId.value && isPublicPage) {
9+
return navigateTo('/user');
10+
}
11+
12+
// Is not authenticated and trying to access a protected page
13+
if (!userId.value && isProtectedPage) {
14+
return navigateTo('/sign-in');
15+
}
16+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default defineNuxtConfig({
2+
modules: ['@clerk/nuxt'],
3+
// The code below is only necessary in our test environment.
4+
// Env vars are automatically read by Nuxt. See https://nuxt.com/docs/guide/going-further/runtime-config
5+
runtimeConfig: {
6+
public: {
7+
clerk: {
8+
publishableKey: process.env.NUXT_PUBLIC_CLERK_PUBLISHABLE_KEY,
9+
},
10+
},
11+
clerk: {
12+
secretKey: process.env.CLERK_SECRET_KEY,
13+
},
14+
},
15+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "nuxt-clerk-integration-template",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"build": "nuxt build",
7+
"dev": "nuxt dev --port $PORT",
8+
"generate": "nuxt generate",
9+
"postinstall": "nuxt prepare",
10+
"preview": "nuxt preview --port $PORT"
11+
},
12+
"dependencies": {
13+
"nuxt": "^3.14.159",
14+
"vue": "^3.5.12",
15+
"vue-router": "^4.4.5"
16+
}
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<template>
2+
<div>
3+
<h1>Index Route</h1>
4+
<SignedIn>
5+
<p>You are signed in!</p>
6+
<div>
7+
<p>View your profile here</p>
8+
<UserButton />
9+
<OrganizationSwitcher />
10+
</div>
11+
<div>
12+
<SignOutButton />
13+
</div>
14+
</SignedIn>
15+
<SignedOut>
16+
<p>You are signed out</p>
17+
18+
<SignIn />
19+
</SignedOut>
20+
</div>
21+
</template>

0 commit comments

Comments
 (0)