The static export now works away from the oTunes server. It picks a server at /server (saved in localStorage), connects Convex to it, and loads covers, avatars and streams from it. Streams and avatars pass the session token as a `token` query parameter, which the song and avatar routes accept alongside the cookie. The server allows any origin on /api. Electron serves that export from 127.0.0.1:47836 and drops the bundled Next.js server, the media gateway, symlink materializing and Sharp pruning. The same export can ship in a Tauri app. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import {
|
|
convexAuthNextjsMiddleware,
|
|
createRouteMatcher,
|
|
nextjsMiddlewareRedirect,
|
|
} from "@convex-dev/auth/nextjs/server"
|
|
import { getConvexServerUrl } from "@/lib/convex-server"
|
|
|
|
const isAuthPage = createRouteMatcher(["/signin", "/signup"])
|
|
const isPublic = createRouteMatcher([
|
|
// Song routes check the session themselves, from the cookie or a `token`
|
|
// query parameter (static exports on another origin).
|
|
"/api/song/(.*)",
|
|
"/api/album/:id/cover",
|
|
"/api/artist/:id/cover",
|
|
"/api/playlist/:id/cover",
|
|
// Mobile clients load avatars without the web auth cookie.
|
|
"/api/user/:id/avatar",
|
|
"/album",
|
|
"/album/:id",
|
|
"/artist",
|
|
"/artist/:id",
|
|
"/playlist",
|
|
"/playlist/:id",
|
|
])
|
|
|
|
const authMiddleware = convexAuthNextjsMiddleware(
|
|
async (request, { convexAuth }) => {
|
|
if (isPublic(request)) {
|
|
return
|
|
}
|
|
|
|
const authenticated = await convexAuth.isAuthenticated()
|
|
|
|
if (isAuthPage(request) && authenticated) {
|
|
return nextjsMiddlewareRedirect(request, "/")
|
|
}
|
|
|
|
if (!isAuthPage(request) && !authenticated) {
|
|
return nextjsMiddlewareRedirect(request, "/signin")
|
|
}
|
|
},
|
|
{ convexUrl: getConvexServerUrl() }
|
|
)
|
|
|
|
export default authMiddleware
|
|
|
|
export const config = {
|
|
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"],
|
|
}
|