Feature: Add an onboarding page and redirect users to that page if the user is not logged in. Have 3 sample latest question an... - #99
Open
lazydev-issue-resolver[bot] wants to merge 1 commit into
Conversation
Generated autonomously by LazyDev.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #98
Generated autonomously by LazyDev.
Implementation Plan
IMPLEMENTATION PLAN
Goal: Add a public onboarding page at
/onboardingthat shows a greeting plus three latest sample Q&A entries, and redirect unauthenticated users away from protected app pages to that onboarding page.Create
app/onboarding/page.tsx(new file)OnboardingPage.new Date().getHours():lib/mongodb.ts, matching the query/sort/status logic already used by the home page andapp/api/route handlers (e.g., approved questions sorted bycreatedAtdescending, limited to 3).app/page.tsx,components/home/, andcomponents/question-card.tsxwhere possible (Tailwind + shadcn Card/Button).app/login/page.tsx.Ensure
components/auth-provider.tsxexposes the auth state needed for guardsuser(orisAuthenticated) andloading.loadingis not currently exposed, add it so guards can wait for session restore before deciding where to redirect. This prevents an unwanted flash of the onboarding page for logged-in users.useAuth(), is exported from this file and can be consumed by new guard components.Create
components/auth-guard.tsx(new reusable component)AuthGuardwith props{ children, requireAuth = true }.useAuth()and Next.jsuseRouter().loadingis true, rendernullor a minimal loading state.requireAuthis true and there is nouser, callrouter.replace('/onboarding')in auseEffect.requireAuthis false (for public pages like onboarding/login) and auserexists, callrouter.replace('/').children.Protect existing main app routes
app/page.tsxwith<AuthGuard>(or wrap its returned JSX with a small client wrapper if the page is a server component).app/admin/page.tsxwith the same guard so admin routes are also protected.app/(main)/layout.tsxthat wraps all protected pages inAuthGuard, while leaving/onboardingand/loginoutside the group. URLs remain unchanged. If this route group is used, moveapp/page.tsx→app/(main)/page.tsxandapp/admin/page.tsx→app/(main)/admin/page.tsx. This centralizes auth protection for all present and future app pages. If a minimal change is preferred, applyAuthGuarddirectly in the two pages listed above.Make
/onboardingpublic but redirect logged-in users awayapp/onboarding/page.tsxin<AuthGuard requireAuth={false}>(via a small client wrapper if the page itself is a server component)./onboardingare redirected back to the home page.Wire “latest questions” data source
app/api/to see whether there is already a GET endpoint returning a question list.app/onboarding/page.tsx(server-side fetch) and map the first 3 results to Q&A cards.app/api/questions/latest/route.tsthat:lib/mongodb.ts.createdAt.{ questions: [...] }.components/onboarding/sample-questions.tsx, to render each Q&A consistently if reusingcomponents/question-card.tsxdoes not naturally show the answer.Styling and UX
app/page.tsxandcomponents/home/./loginand optionally a secondary “Browse questions” link that only works when authenticated.Final wiring and validation
app/layout.tsx(or the nearest root layout) already mountsComponents/auth-provider.tsxsoAuthGuardcan access auth state; if not, add the provider there./or/adminredirects to/onboarding./onboardingredirects to/./onboardingshows greeting and exactly 3 sample Q&A entries, with fallback content when the DB is empty.