-
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.
The issue might be the re-export stuff, so fix that!
- Loading branch information
LanDinh
committed
Dec 20, 2024
1 parent
53c1651
commit 95db0e3
Showing
12 changed files
with
141 additions
and
120 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 was deleted.
Oops, something went wrong.
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,5 +1,56 @@ | ||
import { meta, handle, action, LoginRoute } from './login' | ||
import type { MetaFunction, ActionFunctionArgs } from '@remix-run/node' | ||
import { data } from '@remix-run/node' | ||
import { Form } from '@remix-run/react' | ||
import { useContext } from 'react' | ||
import { AppContext } from '../home/document' | ||
import { breadcrumb } from '../navigation/breadcrumb' | ||
import { loginNavigationData } from '../navigation/commonNavigationData' | ||
import { Session } from './session.server' | ||
|
||
|
||
export default LoginRoute | ||
export { meta, handle, action } | ||
export const handle = { | ||
...breadcrumb(loginNavigationData), | ||
} | ||
|
||
|
||
export const meta: MetaFunction = () => { | ||
const appContext = useContext(AppContext) // eslint-disable-line react-hooks/rules-of-hooks | ||
|
||
return [ | ||
{ title: `Login | ${appContext.title}` }, | ||
{ name: 'description', content: 'Identify yourself!' }, | ||
] | ||
} | ||
|
||
export async function action({ request }: ActionFunctionArgs) { | ||
const session = new Session() | ||
await session.init(request) | ||
const form = await request.formData() | ||
const user = form.get('user') | ||
|
||
if ('string' !== typeof user) { | ||
return data({ fieldErrors: { user: 'wrong type' }, formError: null }, { status: 400 }) | ||
} | ||
|
||
return session.create(user, '/') | ||
} | ||
|
||
|
||
export default function LoginRoute(): JSX.Element { | ||
return ( | ||
<div> | ||
<h1>Login</h1> | ||
<section><Form method="post"> | ||
<label> | ||
<input type="radio" name="user" value="user" defaultChecked /> | ||
user | ||
</label> | ||
<label> | ||
<input type="radio" name="user" value="admin" /> | ||
admin | ||
</label> | ||
<button type="submit" className="button" name="action">Login</button> | ||
</Form></section> | ||
</div> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
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,5 +1,40 @@ | ||
import { meta, handle, action, LogoutRoute } from './logout' | ||
import type { MetaFunction, ActionFunctionArgs } from '@remix-run/node' | ||
import { Form } from '@remix-run/react' | ||
import { useContext } from 'react' | ||
import { AppContext } from '../home/document' | ||
import { breadcrumb } from '../navigation/breadcrumb' | ||
import { logoutNavigationData } from '../navigation/commonNavigationData' | ||
import { Session } from './session.server' | ||
|
||
|
||
export default LogoutRoute | ||
export { meta, handle, action } | ||
export const handle = { | ||
...breadcrumb(logoutNavigationData), | ||
} | ||
|
||
|
||
export const meta: MetaFunction = () => { | ||
const appContext = useContext(AppContext) // eslint-disable-line react-hooks/rules-of-hooks | ||
|
||
return [ | ||
{ title: `Logout | ${appContext.title}` }, | ||
{ name: 'description', content: 'Logout.' }, | ||
] | ||
} | ||
|
||
export async function action({ request }: ActionFunctionArgs) { | ||
const session = new Session() | ||
await session.init(request) | ||
return session.destroy('/') | ||
} | ||
|
||
|
||
export default function LogoutRoute(): JSX.Element { | ||
return ( | ||
<div> | ||
<h1>Logout</h1> | ||
<section><Form method="post"> | ||
<button type="submit" className="button" name="action">Logout</button> | ||
</Form></section> | ||
</div> | ||
) | ||
} |
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,17 @@ | ||
import type { LoaderFunctionArgs } from '@remix-run/node' | ||
import { navigationData } from '../../navigationData' | ||
import { | ||
topNavigationData, | ||
bottomNavigationData, | ||
} from '../navigation/commonNavigationData' | ||
import { Session } from '../auth/session.server' | ||
|
||
export async function loader({ request }: LoaderFunctionArgs) { | ||
const session = new Session() | ||
await session.init(request) | ||
return { | ||
top : topNavigationData.filter((data) => session.hasPermission(data.permission)), | ||
middle : navigationData.filter((data) => session.hasPermission(data.permission)), | ||
bottom : bottomNavigationData.filter((data) => session.hasPermission(data.permission)), | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...ontend_tests/tests/testAuth/testLogin.tsx → ...d_tests/tests/testAuth/testLoginRoute.tsx
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
2 changes: 1 addition & 1 deletion
2
...ntend_tests/tests/testAuth/testLogout.tsx → ..._tests/tests/testAuth/testLogoutRoute.tsx
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,24 @@ | ||
// noinspection JSUnresolvedReference | ||
import { vitePlugin as remix } from '@remix-run/dev'; | ||
import { defineConfig } from 'vite'; | ||
export default defineConfig({ | ||
server: { | ||
host: '0.0.0.0', | ||
port: 8000, | ||
}, | ||
plugins: [remix({ | ||
ignoredRouteFiles: ['**/.*'], | ||
// appDirectory: 'app', | ||
// assetsBuildDirectory: 'public/build', | ||
// serverBuildPath: 'build/index.js', | ||
// publicPath: 'build/', | ||
future: { | ||
v3_fetcherPersist: true, | ||
v3_relativeSplatPath: true, | ||
v3_throwAbortReason: true, | ||
v3_lazyRouteDiscovery: true, | ||
v3_singleFetch: true, | ||
v3_routeConfig: true, | ||
}, | ||
})], | ||
}); |
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