[rewrite] Added first steps for authentication

This commit is contained in:
Thastertyn 2025-02-21 16:51:37 +01:00
parent 073f01d070
commit a9c85cefe1
5 changed files with 170 additions and 25 deletions

View File

@ -0,0 +1,100 @@
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Label } from "@/components/ui/label";
export default function MainPage() {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [username, setUsername] = useState("");
return (
<div className="flex min-h-screen flex-col items-center justify-center bg-gray-100 p-6">
{/* Showcase Section */}
<section className="mb-8 w-full max-w-4xl text-center">
<h1 className="mb-4 text-4xl font-bold">Welcome to Our Platform</h1>
<p className="mb-6 text-gray-600">
A place where you can explore, connect, and engage. Sign up or log in
to get started.
</p>
<Button className="px-6 py-2">Learn More</Button>
</section>
{/* Authentication Section */}
<Card className="w-full max-w-md">
<CardHeader>
<CardTitle>Join Us</CardTitle>
</CardHeader>
<CardContent>
<Tabs defaultValue="login" className="w-full">
<TabsList className="grid w-full grid-cols-2">
<TabsTrigger value="login">Login</TabsTrigger>
<TabsTrigger value="register">Register</TabsTrigger>
</TabsList>
{/* Login Tab */}
<TabsContent value="login">
<form className="space-y-4">
<div>
<Label>Email</Label>
<Input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Enter your email"
/>
</div>
<div>
<Label>Password</Label>
<Input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Enter your password"
/>
</div>
<Button className="w-full">Login</Button>
</form>
</TabsContent>
{/* Register Tab */}
<TabsContent value="register">
<form className="space-y-4">
<div>
<Label>Username</Label>
<Input
type="text"
value={username}
onChange={(e) => setUsername(e.target.value)}
placeholder="Choose a username"
/>
</div>
<div>
<Label>Email</Label>
<Input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Enter your email"
/>
</div>
<div>
<Label>Password</Label>
<Input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Create a password"
/>
</div>
<Button className="w-full">Register</Button>
</form>
</TabsContent>
</Tabs>
</CardContent>
</Card>
</div>
);
}

View File

@ -14,10 +14,11 @@ import { createFileRoute } from '@tanstack/react-router'
import { Route as rootRoute } from './routes/__root' import { Route as rootRoute } from './routes/__root'
import { Route as AuthenticatedRouteImport } from './routes/_authenticated/route' import { Route as AuthenticatedRouteImport } from './routes/_authenticated/route'
import { Route as AuthenticatedIndexImport } from './routes/_authenticated/index' import { Route as IndexImport } from './routes/index'
import { Route as authSignInImport } from './routes/(auth)/sign-in' import { Route as authSignInImport } from './routes/(auth)/sign-in'
import { Route as authOtpImport } from './routes/(auth)/otp' import { Route as authOtpImport } from './routes/(auth)/otp'
import { Route as auth500Import } from './routes/(auth)/500' import { Route as auth500Import } from './routes/(auth)/500'
import { Route as AuthenticatedDashboardIndexImport } from './routes/_authenticated/dashboard/index'
// Create Virtual Routes // Create Virtual Routes
@ -75,10 +76,10 @@ const AuthenticatedRouteRoute = AuthenticatedRouteImport.update({
getParentRoute: () => rootRoute, getParentRoute: () => rootRoute,
} as any) } as any)
const AuthenticatedIndexRoute = AuthenticatedIndexImport.update({ const IndexRoute = IndexImport.update({
id: '/', id: '/',
path: '/', path: '/',
getParentRoute: () => AuthenticatedRouteRoute, getParentRoute: () => rootRoute,
} as any) } as any)
const errors503LazyRoute = errors503LazyImport const errors503LazyRoute = errors503LazyImport
@ -239,6 +240,13 @@ const AuthenticatedAppsIndexLazyRoute = AuthenticatedAppsIndexLazyImport.update(
import('./routes/_authenticated/apps/index.lazy').then((d) => d.Route), import('./routes/_authenticated/apps/index.lazy').then((d) => d.Route),
) )
const AuthenticatedDashboardIndexRoute =
AuthenticatedDashboardIndexImport.update({
id: '/dashboard/',
path: '/dashboard/',
getParentRoute: () => AuthenticatedRouteRoute,
} as any)
const AuthenticatedSettingsNotificationsLazyRoute = const AuthenticatedSettingsNotificationsLazyRoute =
AuthenticatedSettingsNotificationsLazyImport.update({ AuthenticatedSettingsNotificationsLazyImport.update({
id: '/notifications', id: '/notifications',
@ -287,6 +295,13 @@ const AuthenticatedSettingsAccountLazyRoute =
declare module '@tanstack/react-router' { declare module '@tanstack/react-router' {
interface FileRoutesByPath { interface FileRoutesByPath {
'/': {
id: '/'
path: '/'
fullPath: '/'
preLoaderRoute: typeof IndexImport
parentRoute: typeof rootRoute
}
'/_authenticated': { '/_authenticated': {
id: '/_authenticated' id: '/_authenticated'
path: '' path: ''
@ -378,13 +393,6 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof errors503LazyImport preLoaderRoute: typeof errors503LazyImport
parentRoute: typeof rootRoute parentRoute: typeof rootRoute
} }
'/_authenticated/': {
id: '/_authenticated/'
path: '/'
fullPath: '/'
preLoaderRoute: typeof AuthenticatedIndexImport
parentRoute: typeof AuthenticatedRouteImport
}
'/_authenticated/settings/account': { '/_authenticated/settings/account': {
id: '/_authenticated/settings/account' id: '/_authenticated/settings/account'
path: '/account' path: '/account'
@ -413,6 +421,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof AuthenticatedSettingsNotificationsLazyImport preLoaderRoute: typeof AuthenticatedSettingsNotificationsLazyImport
parentRoute: typeof AuthenticatedSettingsRouteLazyImport parentRoute: typeof AuthenticatedSettingsRouteLazyImport
} }
'/_authenticated/dashboard/': {
id: '/_authenticated/dashboard/'
path: '/dashboard'
fullPath: '/dashboard'
preLoaderRoute: typeof AuthenticatedDashboardIndexImport
parentRoute: typeof AuthenticatedRouteImport
}
'/_authenticated/apps/': { '/_authenticated/apps/': {
id: '/_authenticated/apps/' id: '/_authenticated/apps/'
path: '/apps' path: '/apps'
@ -495,7 +510,7 @@ const AuthenticatedSettingsRouteLazyRouteWithChildren =
interface AuthenticatedRouteRouteChildren { interface AuthenticatedRouteRouteChildren {
AuthenticatedSettingsRouteLazyRoute: typeof AuthenticatedSettingsRouteLazyRouteWithChildren AuthenticatedSettingsRouteLazyRoute: typeof AuthenticatedSettingsRouteLazyRouteWithChildren
AuthenticatedIndexRoute: typeof AuthenticatedIndexRoute AuthenticatedDashboardIndexRoute: typeof AuthenticatedDashboardIndexRoute
AuthenticatedAppsIndexLazyRoute: typeof AuthenticatedAppsIndexLazyRoute AuthenticatedAppsIndexLazyRoute: typeof AuthenticatedAppsIndexLazyRoute
AuthenticatedChatsIndexLazyRoute: typeof AuthenticatedChatsIndexLazyRoute AuthenticatedChatsIndexLazyRoute: typeof AuthenticatedChatsIndexLazyRoute
AuthenticatedHelpCenterIndexLazyRoute: typeof AuthenticatedHelpCenterIndexLazyRoute AuthenticatedHelpCenterIndexLazyRoute: typeof AuthenticatedHelpCenterIndexLazyRoute
@ -507,7 +522,7 @@ interface AuthenticatedRouteRouteChildren {
const AuthenticatedRouteRouteChildren: AuthenticatedRouteRouteChildren = { const AuthenticatedRouteRouteChildren: AuthenticatedRouteRouteChildren = {
AuthenticatedSettingsRouteLazyRoute: AuthenticatedSettingsRouteLazyRoute:
AuthenticatedSettingsRouteLazyRouteWithChildren, AuthenticatedSettingsRouteLazyRouteWithChildren,
AuthenticatedIndexRoute: AuthenticatedIndexRoute, AuthenticatedDashboardIndexRoute: AuthenticatedDashboardIndexRoute,
AuthenticatedAppsIndexLazyRoute: AuthenticatedAppsIndexLazyRoute, AuthenticatedAppsIndexLazyRoute: AuthenticatedAppsIndexLazyRoute,
AuthenticatedChatsIndexLazyRoute: AuthenticatedChatsIndexLazyRoute, AuthenticatedChatsIndexLazyRoute: AuthenticatedChatsIndexLazyRoute,
AuthenticatedHelpCenterIndexLazyRoute: AuthenticatedHelpCenterIndexLazyRoute, AuthenticatedHelpCenterIndexLazyRoute: AuthenticatedHelpCenterIndexLazyRoute,
@ -520,6 +535,7 @@ const AuthenticatedRouteRouteWithChildren =
AuthenticatedRouteRoute._addFileChildren(AuthenticatedRouteRouteChildren) AuthenticatedRouteRoute._addFileChildren(AuthenticatedRouteRouteChildren)
export interface FileRoutesByFullPath { export interface FileRoutesByFullPath {
'/': typeof IndexRoute
'': typeof AuthenticatedRouteRouteWithChildren '': typeof AuthenticatedRouteRouteWithChildren
'/500': typeof errors500LazyRoute '/500': typeof errors500LazyRoute
'/otp': typeof authOtpRoute '/otp': typeof authOtpRoute
@ -532,11 +548,11 @@ export interface FileRoutesByFullPath {
'/403': typeof errors403LazyRoute '/403': typeof errors403LazyRoute
'/404': typeof errors404LazyRoute '/404': typeof errors404LazyRoute
'/503': typeof errors503LazyRoute '/503': typeof errors503LazyRoute
'/': typeof AuthenticatedIndexRoute
'/settings/account': typeof AuthenticatedSettingsAccountLazyRoute '/settings/account': typeof AuthenticatedSettingsAccountLazyRoute
'/settings/appearance': typeof AuthenticatedSettingsAppearanceLazyRoute '/settings/appearance': typeof AuthenticatedSettingsAppearanceLazyRoute
'/settings/display': typeof AuthenticatedSettingsDisplayLazyRoute '/settings/display': typeof AuthenticatedSettingsDisplayLazyRoute
'/settings/notifications': typeof AuthenticatedSettingsNotificationsLazyRoute '/settings/notifications': typeof AuthenticatedSettingsNotificationsLazyRoute
'/dashboard': typeof AuthenticatedDashboardIndexRoute
'/apps': typeof AuthenticatedAppsIndexLazyRoute '/apps': typeof AuthenticatedAppsIndexLazyRoute
'/chats': typeof AuthenticatedChatsIndexLazyRoute '/chats': typeof AuthenticatedChatsIndexLazyRoute
'/help-center': typeof AuthenticatedHelpCenterIndexLazyRoute '/help-center': typeof AuthenticatedHelpCenterIndexLazyRoute
@ -547,6 +563,8 @@ export interface FileRoutesByFullPath {
} }
export interface FileRoutesByTo { export interface FileRoutesByTo {
'/': typeof IndexRoute
'': typeof AuthenticatedRouteRouteWithChildren
'/500': typeof errors500LazyRoute '/500': typeof errors500LazyRoute
'/otp': typeof authOtpRoute '/otp': typeof authOtpRoute
'/sign-in': typeof authSignInRoute '/sign-in': typeof authSignInRoute
@ -557,11 +575,11 @@ export interface FileRoutesByTo {
'/403': typeof errors403LazyRoute '/403': typeof errors403LazyRoute
'/404': typeof errors404LazyRoute '/404': typeof errors404LazyRoute
'/503': typeof errors503LazyRoute '/503': typeof errors503LazyRoute
'/': typeof AuthenticatedIndexRoute
'/settings/account': typeof AuthenticatedSettingsAccountLazyRoute '/settings/account': typeof AuthenticatedSettingsAccountLazyRoute
'/settings/appearance': typeof AuthenticatedSettingsAppearanceLazyRoute '/settings/appearance': typeof AuthenticatedSettingsAppearanceLazyRoute
'/settings/display': typeof AuthenticatedSettingsDisplayLazyRoute '/settings/display': typeof AuthenticatedSettingsDisplayLazyRoute
'/settings/notifications': typeof AuthenticatedSettingsNotificationsLazyRoute '/settings/notifications': typeof AuthenticatedSettingsNotificationsLazyRoute
'/dashboard': typeof AuthenticatedDashboardIndexRoute
'/apps': typeof AuthenticatedAppsIndexLazyRoute '/apps': typeof AuthenticatedAppsIndexLazyRoute
'/chats': typeof AuthenticatedChatsIndexLazyRoute '/chats': typeof AuthenticatedChatsIndexLazyRoute
'/help-center': typeof AuthenticatedHelpCenterIndexLazyRoute '/help-center': typeof AuthenticatedHelpCenterIndexLazyRoute
@ -573,6 +591,7 @@ export interface FileRoutesByTo {
export interface FileRoutesById { export interface FileRoutesById {
__root__: typeof rootRoute __root__: typeof rootRoute
'/': typeof IndexRoute
'/_authenticated': typeof AuthenticatedRouteRouteWithChildren '/_authenticated': typeof AuthenticatedRouteRouteWithChildren
'/(auth)/500': typeof auth500Route '/(auth)/500': typeof auth500Route
'/(auth)/otp': typeof authOtpRoute '/(auth)/otp': typeof authOtpRoute
@ -586,11 +605,11 @@ export interface FileRoutesById {
'/(errors)/404': typeof errors404LazyRoute '/(errors)/404': typeof errors404LazyRoute
'/(errors)/500': typeof errors500LazyRoute '/(errors)/500': typeof errors500LazyRoute
'/(errors)/503': typeof errors503LazyRoute '/(errors)/503': typeof errors503LazyRoute
'/_authenticated/': typeof AuthenticatedIndexRoute
'/_authenticated/settings/account': typeof AuthenticatedSettingsAccountLazyRoute '/_authenticated/settings/account': typeof AuthenticatedSettingsAccountLazyRoute
'/_authenticated/settings/appearance': typeof AuthenticatedSettingsAppearanceLazyRoute '/_authenticated/settings/appearance': typeof AuthenticatedSettingsAppearanceLazyRoute
'/_authenticated/settings/display': typeof AuthenticatedSettingsDisplayLazyRoute '/_authenticated/settings/display': typeof AuthenticatedSettingsDisplayLazyRoute
'/_authenticated/settings/notifications': typeof AuthenticatedSettingsNotificationsLazyRoute '/_authenticated/settings/notifications': typeof AuthenticatedSettingsNotificationsLazyRoute
'/_authenticated/dashboard/': typeof AuthenticatedDashboardIndexRoute
'/_authenticated/apps/': typeof AuthenticatedAppsIndexLazyRoute '/_authenticated/apps/': typeof AuthenticatedAppsIndexLazyRoute
'/_authenticated/chats/': typeof AuthenticatedChatsIndexLazyRoute '/_authenticated/chats/': typeof AuthenticatedChatsIndexLazyRoute
'/_authenticated/help-center/': typeof AuthenticatedHelpCenterIndexLazyRoute '/_authenticated/help-center/': typeof AuthenticatedHelpCenterIndexLazyRoute
@ -603,6 +622,7 @@ export interface FileRoutesById {
export interface FileRouteTypes { export interface FileRouteTypes {
fileRoutesByFullPath: FileRoutesByFullPath fileRoutesByFullPath: FileRoutesByFullPath
fullPaths: fullPaths:
| '/'
| '' | ''
| '/500' | '/500'
| '/otp' | '/otp'
@ -615,11 +635,11 @@ export interface FileRouteTypes {
| '/403' | '/403'
| '/404' | '/404'
| '/503' | '/503'
| '/'
| '/settings/account' | '/settings/account'
| '/settings/appearance' | '/settings/appearance'
| '/settings/display' | '/settings/display'
| '/settings/notifications' | '/settings/notifications'
| '/dashboard'
| '/apps' | '/apps'
| '/chats' | '/chats'
| '/help-center' | '/help-center'
@ -629,6 +649,8 @@ export interface FileRouteTypes {
| '/users' | '/users'
fileRoutesByTo: FileRoutesByTo fileRoutesByTo: FileRoutesByTo
to: to:
| '/'
| ''
| '/500' | '/500'
| '/otp' | '/otp'
| '/sign-in' | '/sign-in'
@ -639,11 +661,11 @@ export interface FileRouteTypes {
| '/403' | '/403'
| '/404' | '/404'
| '/503' | '/503'
| '/'
| '/settings/account' | '/settings/account'
| '/settings/appearance' | '/settings/appearance'
| '/settings/display' | '/settings/display'
| '/settings/notifications' | '/settings/notifications'
| '/dashboard'
| '/apps' | '/apps'
| '/chats' | '/chats'
| '/help-center' | '/help-center'
@ -653,6 +675,7 @@ export interface FileRouteTypes {
| '/users' | '/users'
id: id:
| '__root__' | '__root__'
| '/'
| '/_authenticated' | '/_authenticated'
| '/(auth)/500' | '/(auth)/500'
| '/(auth)/otp' | '/(auth)/otp'
@ -666,11 +689,11 @@ export interface FileRouteTypes {
| '/(errors)/404' | '/(errors)/404'
| '/(errors)/500' | '/(errors)/500'
| '/(errors)/503' | '/(errors)/503'
| '/_authenticated/'
| '/_authenticated/settings/account' | '/_authenticated/settings/account'
| '/_authenticated/settings/appearance' | '/_authenticated/settings/appearance'
| '/_authenticated/settings/display' | '/_authenticated/settings/display'
| '/_authenticated/settings/notifications' | '/_authenticated/settings/notifications'
| '/_authenticated/dashboard/'
| '/_authenticated/apps/' | '/_authenticated/apps/'
| '/_authenticated/chats/' | '/_authenticated/chats/'
| '/_authenticated/help-center/' | '/_authenticated/help-center/'
@ -682,6 +705,7 @@ export interface FileRouteTypes {
} }
export interface RootRouteChildren { export interface RootRouteChildren {
IndexRoute: typeof IndexRoute
AuthenticatedRouteRoute: typeof AuthenticatedRouteRouteWithChildren AuthenticatedRouteRoute: typeof AuthenticatedRouteRouteWithChildren
auth500Route: typeof auth500Route auth500Route: typeof auth500Route
authOtpRoute: typeof authOtpRoute authOtpRoute: typeof authOtpRoute
@ -697,6 +721,7 @@ export interface RootRouteChildren {
} }
const rootRouteChildren: RootRouteChildren = { const rootRouteChildren: RootRouteChildren = {
IndexRoute: IndexRoute,
AuthenticatedRouteRoute: AuthenticatedRouteRouteWithChildren, AuthenticatedRouteRoute: AuthenticatedRouteRouteWithChildren,
auth500Route: auth500Route, auth500Route: auth500Route,
authOtpRoute: authOtpRoute, authOtpRoute: authOtpRoute,
@ -721,6 +746,7 @@ export const routeTree = rootRoute
"__root__": { "__root__": {
"filePath": "__root.tsx", "filePath": "__root.tsx",
"children": [ "children": [
"/",
"/_authenticated", "/_authenticated",
"/(auth)/500", "/(auth)/500",
"/(auth)/otp", "/(auth)/otp",
@ -735,11 +761,14 @@ export const routeTree = rootRoute
"/(errors)/503" "/(errors)/503"
] ]
}, },
"/": {
"filePath": "index.tsx"
},
"/_authenticated": { "/_authenticated": {
"filePath": "_authenticated/route.tsx", "filePath": "_authenticated/route.tsx",
"children": [ "children": [
"/_authenticated/settings", "/_authenticated/settings",
"/_authenticated/", "/_authenticated/dashboard/",
"/_authenticated/apps/", "/_authenticated/apps/",
"/_authenticated/chats/", "/_authenticated/chats/",
"/_authenticated/help-center/", "/_authenticated/help-center/",
@ -792,10 +821,6 @@ export const routeTree = rootRoute
"/(errors)/503": { "/(errors)/503": {
"filePath": "(errors)/503.lazy.tsx" "filePath": "(errors)/503.lazy.tsx"
}, },
"/_authenticated/": {
"filePath": "_authenticated/index.tsx",
"parent": "/_authenticated"
},
"/_authenticated/settings/account": { "/_authenticated/settings/account": {
"filePath": "_authenticated/settings/account.lazy.tsx", "filePath": "_authenticated/settings/account.lazy.tsx",
"parent": "/_authenticated/settings" "parent": "/_authenticated/settings"
@ -812,6 +837,10 @@ export const routeTree = rootRoute
"filePath": "_authenticated/settings/notifications.lazy.tsx", "filePath": "_authenticated/settings/notifications.lazy.tsx",
"parent": "/_authenticated/settings" "parent": "/_authenticated/settings"
}, },
"/_authenticated/dashboard/": {
"filePath": "_authenticated/dashboard/index.tsx",
"parent": "/_authenticated"
},
"/_authenticated/apps/": { "/_authenticated/apps/": {
"filePath": "_authenticated/apps/index.lazy.tsx", "filePath": "_authenticated/apps/index.lazy.tsx",
"parent": "/_authenticated" "parent": "/_authenticated"

View File

@ -1,6 +1,6 @@
import { createFileRoute } from "@tanstack/react-router"; import { createFileRoute } from "@tanstack/react-router";
import Dashboard from "@/pages/dashboard"; import Dashboard from "@/pages/dashboard";
export const Route = createFileRoute("/_authenticated/")({ export const Route = createFileRoute("/_authenticated/dashboard/")({
component: Dashboard component: Dashboard
}); });

View File

@ -1,5 +1,5 @@
import Cookies from "js-cookie"; import Cookies from "js-cookie";
import { createFileRoute, Outlet } from "@tanstack/react-router"; import { createFileRoute, Outlet, redirect } from "@tanstack/react-router";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { SearchProvider } from "@/context/search-context"; import { SearchProvider } from "@/context/search-context";
import { SidebarProvider } from "@/components/ui/sidebar"; import { SidebarProvider } from "@/components/ui/sidebar";
@ -7,6 +7,16 @@ import { AppSidebar } from "@/components/layout/app-sidebar";
import SkipToMain from "@/components/skip-to-main"; import SkipToMain from "@/components/skip-to-main";
export const Route = createFileRoute("/_authenticated")({ export const Route = createFileRoute("/_authenticated")({
beforeLoad: async ({ location }) => {
if (true) {
throw redirect({
to: "/sign-in",
search: {
redirect: location.href
}
});
}
},
component: RouteComponent component: RouteComponent
}); });

View File

@ -0,0 +1,6 @@
import { createFileRoute } from "@tanstack/react-router";
import MainPage from "@/pages/home";
export const Route = createFileRoute("/")({
component: MainPage
});