@@ -42,8 +34,6 @@ export function TopicSections({
setActiveIndex={setActiveIndex}
startIndex={sections.slice(0, sectionIndex).reduce((acc, s) => acc + (s?.links?.length || 0), 0)}
linkRefs={linkRefs}
- me={me}
- personalLinks={personalLinks}
/>
)
)}
diff --git a/web/hooks/use-topic-data.ts b/web/hooks/use-topic-data.ts
new file mode 100644
index 00000000..8280762b
--- /dev/null
+++ b/web/hooks/use-topic-data.ts
@@ -0,0 +1,15 @@
+import { useMemo } from "react"
+import { useCoState } from "@/lib/providers/jazz-provider"
+import { PublicGlobalGroup } from "@/lib/schema/master/public-group"
+import { Account, AnonymousJazzAgent, ID } from "jazz-tools"
+import { Link, Topic } from "@/lib/schema"
+
+const GLOBAL_GROUP_ID = process.env.NEXT_PUBLIC_JAZZ_GLOBAL_GROUP as ID
+
+export function useTopicData(topicName: string, me: Account | AnonymousJazzAgent | undefined) {
+ const topicID = useMemo(() => me && Topic.findUnique({ topicName }, GLOBAL_GROUP_ID, me), [topicName, me])
+
+ const topic = useCoState(Topic, topicID, { latestGlobalGuide: { sections: [{ links: [] }] } })
+
+ return { topic }
+}
diff --git a/web/lib/providers/jazz-provider.tsx b/web/lib/providers/jazz-provider.tsx
index e5b8fb80..3ca9ca9a 100644
--- a/web/lib/providers/jazz-provider.tsx
+++ b/web/lib/providers/jazz-provider.tsx
@@ -3,104 +3,27 @@
import { createJazzReactApp } from "jazz-react"
import { LaAccount } from "@/lib/schema"
import { useClerk } from "@clerk/nextjs"
-import { createContext, useMemo, useState } from "react"
-import { AuthMethodCtx } from "jazz-react"
+import { useJazzClerkAuth } from "jazz-react-auth-clerk"
const Jazz = createJazzReactApp({
AccountSchema: LaAccount
})
-export const { useAccount, useCoState, useAcceptInvite } = Jazz
+export const { useAccount, useAccountOrGuest, useCoState, useAcceptInvite } = Jazz
-export function JazzProvider({ children }: { children: React.ReactNode }) {
- return {children}
-}
-
-export const JazzClerkAuthCtx = createContext<{
- errors: string[]
-}>({
- errors: []
-})
-
-export function JazzClerkAuth({ children }: { children: React.ReactNode }) {
+export function JazzAndAuth({ children }: { children: React.ReactNode }) {
const clerk = useClerk()
- const [errors, setErrors] = useState([])
- const authMethod = useMemo(() => {
- return new BrowserClerkAuth(
- {
- onError: error => {
- void clerk.signOut()
- setErrors(errors => [...errors, error.toString()])
- }
- },
- clerk
- )
- }, [clerk])
+ const [auth, state] = useJazzClerkAuth(clerk)
return (
-
- {children}
-
+ <>
+ {state.errors.map((error) => (
+ {error}
+ ))}
+
+ {children}
+
+ >
)
-}
-
-import { Account, AuthMethod, AuthResult, ID } from "jazz-tools"
-import type { LoadedClerk } from "@clerk/types"
-import { AgentSecret } from "cojson"
-
-export class BrowserClerkAuth implements AuthMethod {
- constructor(
- public driver: BrowserClerkAuth.Driver,
- private readonly clerkClient: LoadedClerk
- ) {}
-
- async start(): Promise {
- if (this.clerkClient.user) {
- const storedCredentials = this.clerkClient.user.unsafeMetadata
- if (storedCredentials.jazzAccountID) {
- if (!storedCredentials.jazzAccountSecret) {
- throw new Error("No secret for existing user")
- }
- return {
- type: "existing",
- credentials: {
- accountID: storedCredentials.jazzAccountID as ID,
- secret: storedCredentials.jazzAccountSecret as AgentSecret
- },
- onSuccess: () => {},
- onError: (error: string | Error) => {
- this.driver.onError(error)
- }
- }
- } else {
- return {
- type: "new",
- creationProps: {
- name: this.clerkClient.user.fullName || this.clerkClient.user.username || this.clerkClient.user.id
- },
- saveCredentials: async (credentials: { accountID: ID; secret: AgentSecret }) => {
- await this.clerkClient.user?.update({
- unsafeMetadata: {
- jazzAccountID: credentials.accountID,
- jazzAccountSecret: credentials.secret
- }
- })
- },
- onSuccess: () => {},
- onError: (error: string | Error) => {
- this.driver.onError(error)
- }
- }
- }
- } else {
- throw new Error("Not signed in")
- }
- }
-}
-
-export namespace BrowserClerkAuth {
- export interface Driver {
- onError: (error: string | Error) => void
- }
-}
+}
\ No newline at end of file
diff --git a/web/middleware.ts b/web/middleware.ts
index 3059c4a8..92bdc125 100644
--- a/web/middleware.ts
+++ b/web/middleware.ts
@@ -1,19 +1,23 @@
-import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server"
+import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server'
-const publicRoutes = ["/", "/sign-in(.*)", "/sign-up(.*)"]
-const isPublicRoute = createRouteMatcher(publicRoutes)
+const isPublicRoute = createRouteMatcher([
+ '/sign-in(.*)',
+ '/sign-up(.*)',
+ '/',
+ '/:topicName(.*)'
+])
export default clerkMiddleware((auth, request) => {
- if (!isPublicRoute(request)) {
- auth().protect()
- }
+ if (!isPublicRoute(request)) {
+ auth().protect()
+ }
})
export const config = {
- matcher: [
- // Skip Next.js internals and all static files, unless found in search params
- "/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)",
- // Always run for API routes
- "/(api|trpc)(.*)"
- ]
+ matcher: [
+ // Skip Next.js internals and all static files, unless found in search params
+ '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
+ // Always run for API routes
+ '/(api|trpc)(.*)'
+ ]
}
diff --git a/web/package.json b/web/package.json
index 0009e03b..50c1db55 100644
--- a/web/package.json
+++ b/web/package.json
@@ -70,9 +70,10 @@
"date-fns": "^3.6.0",
"framer-motion": "^11.5.4",
"geist": "^1.3.1",
- "jazz-react": "0.7.35-unique.2",
- "jazz-react-auth-clerk": "0.7.33-new-auth.1",
- "jazz-tools": "0.7.35-unique.2",
+ "jazz-react": "0.7.35-guest-auth.5",
+ "jazz-browser-auth-clerk": "0.7.35-guest-auth.5",
+ "jazz-react-auth-clerk": "0.7.35-guest-auth.5",
+ "jazz-tools": "0.7.35-guest-auth.5",
"jotai": "^2.9.3",
"lowlight": "^3.1.0",
"lucide-react": "^0.429.0",