-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ffd826
commit c72bb8b
Showing
13 changed files
with
134 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
providers: [ | ||
{ | ||
domain: process.env.CONVEX_SITE_URL, | ||
applicationID: "convex", | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { convexAuth } from "@convex-dev/auth/server"; | ||
|
||
export const { auth, signIn, signOut, store } = convexAuth({ | ||
providers: [], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { httpRouter } from "convex/server"; | ||
import { auth } from "./auth"; | ||
|
||
const http = httpRouter(); | ||
|
||
auth.addHttpRoutes(http); | ||
|
||
export default http; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { defineSchema } from "convex/server"; | ||
import { authTables } from "@convex-dev/auth/server"; | ||
|
||
const schema = defineSchema({ | ||
...authTables, | ||
}); | ||
|
||
export default schema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from "react"; | ||
|
||
function SignInPage() { | ||
return <div>SignInPage</div>; | ||
} | ||
|
||
export default SignInPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from "react"; | ||
|
||
function page() { | ||
return <div>page</div>; | ||
} | ||
|
||
export default page; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
"use client"; | ||
|
||
import { ConvexProvider, ConvexReactClient } from "convex/react"; | ||
import { ConvexAuthNextjsProvider } from "@convex-dev/auth/nextjs"; | ||
import { ConvexReactClient } from "convex/react"; | ||
import { ReactNode } from "react"; | ||
|
||
const convex = new ConvexReactClient(process.env.NEXT_PUBLIC_CONVEX_URL!); | ||
|
||
export function ConvexClientProvider({ children }: { children: ReactNode }) { | ||
return <ConvexProvider client={convex}>{children}</ConvexProvider>; | ||
return ( | ||
<ConvexAuthNextjsProvider client={convex}> | ||
{children} | ||
</ConvexAuthNextjsProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { | ||
convexAuthNextjsMiddleware, | ||
createRouteMatcher, | ||
isAuthenticatedNextjs, | ||
nextjsMiddlewareRedirect, | ||
} from "@convex-dev/auth/nextjs/server"; | ||
|
||
const isSignInPage = createRouteMatcher(["/signin"]); | ||
|
||
export default convexAuthNextjsMiddleware((request) => { | ||
const method = request.method; | ||
console.log(request); | ||
|
||
const isAuthenticated = isAuthenticatedNextjs(); | ||
console.log("Is Authenticated: ", isAuthenticated); | ||
console.log("Is Sign In Page: ", isSignInPage(request)); | ||
|
||
// Allow GET requests without side-effects | ||
if (method === "GET") { | ||
console.log("Allowing GET request without redirect"); | ||
return; | ||
} | ||
|
||
// Redirect if not authenticated and the request isn't a GET or sign-in request | ||
if (!isSignInPage(request) && !isAuthenticated) { | ||
console.log("Redirecting to /signin"); | ||
return nextjsMiddlewareRedirect(request, "/signin"); | ||
} | ||
}); | ||
|
||
convexAuthNextjsMiddleware(); | ||
export const config = { | ||
// The following matcher runs middleware on all routes except static assets | ||
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"], | ||
}; |