Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/blog-next/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ WORKOS_REDIRECT_URI=
WORKOS_SESSION_COOKIE=
CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
CLERK_JWT_KEY=
CLERK_API_URL=
CLERK_FRONTEND_API=
CLERK_REDIRECT_URI=
CLERK_SESSION_COOKIE=

BROADCAST_CONNECTION=holo
Expand Down
10 changes: 10 additions & 0 deletions apps/blog-next/app/api/auth/clerk/callback/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { completeClerkAuth } from '@holo-js/auth-clerk'

export async function GET(request: Request) {
const result = await completeClerkAuth(request)
if (!result.ok) {
return Response.redirect(new URL(`/login?error=${encodeURIComponent(result.code)}`, request.url))
}

return Response.redirect(new URL('/admin', request.url))
}
5 changes: 5 additions & 0 deletions apps/blog-next/app/api/auth/clerk/login/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { loginWithClerk } from '@holo-js/auth-clerk'

export async function GET(request: Request) {
return await loginWithClerk(request)
}
10 changes: 10 additions & 0 deletions apps/blog-next/app/api/auth/clerk/logout/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { logoutWithClerk } from '@holo-js/auth-clerk'

export async function POST(request: Request) {
const result = await logoutWithClerk(request)
if (!result.ok) {
return Response.json(result, { status: 422 })
}

return Response.redirect(result.url, 303)
}
5 changes: 5 additions & 0 deletions apps/blog-next/app/api/auth/clerk/register/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { registerWithClerk } from '@holo-js/auth-clerk'

export async function GET(request: Request) {
return await registerWithClerk(request)
}
3 changes: 3 additions & 0 deletions apps/blog-next/app/auth-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export function AuthNav() {
<form action="/api/auth/workos/logout" method="post" style={logoutFormStyle}>
<button type="submit" style={logoutButtonStyle}>Logout from WorkOS</button>
</form>
<form action="/api/auth/clerk/logout" method="post" style={logoutFormStyle}>
<button type="submit" style={logoutButtonStyle}>Logout from Clerk</button>
</form>
</>
)
}
1 change: 1 addition & 0 deletions apps/blog-next/app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default function LoginPage() {
<a href="/auth/google" style={{ color: '#e5e7eb', textDecoration: 'none' }}>Continue with Google</a>
<a href="/auth/github" style={{ color: '#e5e7eb', textDecoration: 'none' }}>Continue with GitHub</a>
<a href="/api/auth/workos/login" style={{ color: '#e5e7eb', textDecoration: 'none' }}>Continue with WorkOS</a>
<a href="/api/auth/clerk/login" style={{ color: '#e5e7eb', textDecoration: 'none' }}>Continue with Clerk</a>
</div>

<form onSubmit={(event) => { event.preventDefault(); form.submit() }} style={{ display: 'grid', gap: '0.9rem' }}>
Expand Down
1 change: 1 addition & 0 deletions apps/blog-next/app/register/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default function RegisterPage() {

<Link href="/login" style={{ color: '#7dd3fc' }}>Already have an account?</Link>
<a href="/api/auth/workos/register" style={{ color: '#7dd3fc' }}>Register with WorkOS</a>
<a href="/api/auth/clerk/register" style={{ color: '#7dd3fc' }}>Register with Clerk</a>
</section>
)
}
5 changes: 3 additions & 2 deletions apps/blog-next/config/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ export default defineAuthConfig({
},
// Add a dedicated guard and provider if WorkOS users should resolve through a different model.
clerk: {
provider: env('AUTH_CLERK_PROVIDER', 'app'),
app: {
publishableKey: env('CLERK_PUBLISHABLE_KEY'),
secretKey: env('CLERK_SECRET_KEY'),
jwtKey: env('CLERK_JWT_KEY'),
apiUrl: env('CLERK_API_URL'),
frontendApi: env('CLERK_FRONTEND_API'),
sessionCookie: env('CLERK_SESSION_COOKIE', "__session"),
redirectUri: env('CLERK_REDIRECT_URI'),
sessionCookie: env('CLERK_SESSION_COOKIE', '__session'),
},
},
// Add a dedicated guard and provider if Clerk users should resolve through a different model.
Expand Down
6 changes: 3 additions & 3 deletions apps/blog-nuxt/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ WORKOS_API_KEY=
WORKOS_COOKIE_PASSWORD=
WORKOS_REDIRECT_URI=
WORKOS_SESSION_COOKIE=
CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
CLERK_JWT_KEY=
CLERK_API_URL=
CLERK_FRONTEND_API=
CLERK_PUBLISHABLE_KEY=
CLERK_REDIRECT_URI=
CLERK_SECRET_KEY=
CLERK_SESSION_COOKIE=

BROADCAST_CONNECTION=holo
Expand Down
3 changes: 3 additions & 0 deletions apps/blog-nuxt/app/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ async function logout() {
<form action="/api/auth/workos/logout" method="post" class="logout-form">
<button type="submit" class="logout-button">Logout from WorkOS</button>
</form>
<form action="/api/auth/clerk/logout" method="post" class="logout-form">
<button type="submit" class="logout-button">Logout from Clerk</button>
</form>
</template>
<template v-else>
<NuxtLink to="/login">Login</NuxtLink>
Expand Down
1 change: 1 addition & 0 deletions apps/blog-nuxt/app/pages/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const form = useForm(loginForm, {
<a href="/auth/google">Continue with Google</a>
<a href="/auth/github">Continue with GitHub</a>
<a href="/api/auth/workos/login">Continue with WorkOS</a>
<a href="/api/auth/clerk/login">Continue with Clerk</a>
</div>

<form class="stack" @submit.prevent="form.submit()">
Expand Down
1 change: 1 addition & 0 deletions apps/blog-nuxt/app/pages/register/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const form = useForm(registerForm, {

<NuxtLink to="/login">Already have an account?</NuxtLink>
<a href="/api/auth/workos/register">Register with WorkOS</a>
<a href="/api/auth/clerk/register">Register with Clerk</a>
</section>
</template>

Expand Down
5 changes: 3 additions & 2 deletions apps/blog-nuxt/config/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ export default defineAuthConfig({
},
// Add a dedicated guard and provider if WorkOS users should resolve through a different model.
clerk: {
provider: env('AUTH_CLERK_PROVIDER', 'app'),
app: {
publishableKey: env('CLERK_PUBLISHABLE_KEY'),
secretKey: env('CLERK_SECRET_KEY'),
jwtKey: env('CLERK_JWT_KEY'),
apiUrl: env('CLERK_API_URL'),
frontendApi: env('CLERK_FRONTEND_API'),
sessionCookie: env('CLERK_SESSION_COOKIE', "__session"),
redirectUri: env('CLERK_REDIRECT_URI'),
sessionCookie: env('CLERK_SESSION_COOKIE', '__session'),
},
},
// Add a dedicated guard and provider if Clerk users should resolve through a different model.
Expand Down
12 changes: 12 additions & 0 deletions apps/blog-nuxt/server/api/auth/clerk/callback.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { completeClerkAuth } from '@holo-js/auth-clerk'
import { sendRedirect } from 'h3'

export default defineEventHandler(async (event) => {
const result = await completeClerkAuth(event)
if (!result.ok) {
const errCode = result.code ?? 'unknown_error'
return await sendRedirect(event, `/login?error=${encodeURIComponent(errCode)}`, 303)
}

return await sendRedirect(event, '/admin', 303)
})
5 changes: 5 additions & 0 deletions apps/blog-nuxt/server/api/auth/clerk/login.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { loginWithClerk } from '@holo-js/auth-clerk'

export default defineEventHandler(async (event) => {
return await loginWithClerk(event)
})
14 changes: 14 additions & 0 deletions apps/blog-nuxt/server/api/auth/clerk/logout.post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { logoutWithClerk } from '@holo-js/auth-clerk'
import { createError, sendRedirect } from 'h3'

export default defineEventHandler(async (event) => {
const result = await logoutWithClerk(event)
if (!result.ok) {
throw createError({
statusCode: 422,
statusMessage: result.message,
})
}

return await sendRedirect(event, result.url, 303)
})
5 changes: 5 additions & 0 deletions apps/blog-nuxt/server/api/auth/clerk/register.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { registerWithClerk } from '@holo-js/auth-clerk'

export default defineEventHandler(async (event) => {
return await registerWithClerk(event)
})
2 changes: 1 addition & 1 deletion apps/blog-sveltekit/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ WORKOS_REDIRECT_URI=
WORKOS_SESSION_COOKIE=
CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
CLERK_JWT_KEY=
CLERK_API_URL=
CLERK_FRONTEND_API=
CLERK_REDIRECT_URI=
CLERK_SESSION_COOKIE=

BROADCAST_CONNECTION=holo
Expand Down
5 changes: 3 additions & 2 deletions apps/blog-sveltekit/config/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,14 @@ export default defineAuthConfig({
},
// Add a dedicated guard and provider if WorkOS users should resolve through a different model.
clerk: {
provider: env('AUTH_CLERK_PROVIDER', 'app'),
app: {
publishableKey: env('CLERK_PUBLISHABLE_KEY'),
secretKey: env('CLERK_SECRET_KEY'),
jwtKey: env('CLERK_JWT_KEY'),
apiUrl: env('CLERK_API_URL'),
frontendApi: env('CLERK_FRONTEND_API'),
sessionCookie: env('CLERK_SESSION_COOKIE', "__session"),
redirectUri: env('CLERK_REDIRECT_URI'),
sessionCookie: env('CLERK_SESSION_COOKIE', '__session'),
},
},
// Add a dedicated guard and provider if Clerk users should resolve through a different model.
Expand Down
3 changes: 3 additions & 0 deletions apps/blog-sveltekit/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<form action="/api/auth/workos/logout" method="post" class="logout-form">
<button type="submit" class="logout-button">Logout from WorkOS</button>
</form>
<form action="/api/auth/clerk/logout" method="post" class="logout-form">
<button type="submit" class="logout-button">Logout from Clerk</button>
</form>
{:else}
<a href="/login">Login</a>
<a href="/register">Register</a>
Expand Down
11 changes: 11 additions & 0 deletions apps/blog-sveltekit/src/routes/api/auth/clerk/callback/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { redirect, type RequestHandler } from '@sveltejs/kit'
import { completeClerkAuth } from '@holo-js/auth-clerk'

export const GET = (async (event) => {
const result = await completeClerkAuth(event)
if (!result.ok) {
throw redirect(303, `/login?error=${encodeURIComponent(result.code)}`)
}

throw redirect(303, '/admin')
}) satisfies RequestHandler
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { loginWithClerk } from '@holo-js/auth-clerk'
import type { RequestHandler } from './$types'

export const GET = (async (event) => {
return await loginWithClerk(event)
}) satisfies RequestHandler
11 changes: 11 additions & 0 deletions apps/blog-sveltekit/src/routes/api/auth/clerk/logout/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { redirect, type RequestHandler } from '@sveltejs/kit'
import { logoutWithClerk } from '@holo-js/auth-clerk'

export const POST = (async (event) => {
const result = await logoutWithClerk(event)
if (!result.ok) {
return Response.json(result, { status: 422 })
}

throw redirect(303, result.url)
}) satisfies RequestHandler
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { registerWithClerk } from '@holo-js/auth-clerk'
import type { RequestHandler } from './$types'

export const GET = (async (event) => {
return await registerWithClerk(event)
}) satisfies RequestHandler
1 change: 1 addition & 0 deletions apps/blog-sveltekit/src/routes/login/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<a href="/auth/google">Continue with Google</a>
<a href="/auth/github">Continue with GitHub</a>
<a href="/api/auth/workos/login">Continue with WorkOS</a>
<a href="/api/auth/clerk/login">Continue with Clerk</a>
</div>

<form class="stack" on:submit={(event) => { event.preventDefault(); form.submit() }}>
Expand Down
1 change: 1 addition & 0 deletions apps/blog-sveltekit/src/routes/register/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@

<a href="/login" class="link">Already have an account?</a>
<a href="/api/auth/workos/register" class="link">Register with WorkOS</a>
<a href="/api/auth/clerk/register" class="link">Register with Clerk</a>
</section>

<style>
Expand Down
Loading