diff --git a/app/auth/mutations/login.ts b/app/auth/mutations/login.ts index 816eba4..84c9b20 100644 --- a/app/auth/mutations/login.ts +++ b/app/auth/mutations/login.ts @@ -1,7 +1,7 @@ import { SessionContext } from "blitz" import { authenticateUser } from "app/auth/auth-utils" import { LoginInput, LoginInputType } from "../validations" - +export let LogIn = false export default async function login(input: LoginInputType, ctx: { session?: SessionContext } = {}) { // This throws an error if input is invalid const { email, password } = LoginInput.parse(input) @@ -10,6 +10,6 @@ export default async function login(input: LoginInputType, ctx: { session?: Sess const user = await authenticateUser(email, password) await ctx.session!.create({ userId: user.id, roles: [user.role] }) - + LogIn = true return user } diff --git a/app/auth/mutations/logout.ts b/app/auth/mutations/logout.ts index 0103916..b2ca600 100644 --- a/app/auth/mutations/logout.ts +++ b/app/auth/mutations/logout.ts @@ -1,5 +1,4 @@ import { SessionContext } from "blitz" - export default async function logout(_ = null, ctx: { session?: SessionContext } = {}) { return await ctx.session!.revoke() } diff --git a/app/hooks/useCurrentUser.ts b/app/hooks/useCurrentUser.ts index 47ebaf5..3395b41 100644 --- a/app/hooks/useCurrentUser.ts +++ b/app/hooks/useCurrentUser.ts @@ -1,6 +1,5 @@ import { useQuery, useSession } from "blitz" import getCurrentUser from "app/users/queries/getCurrentUser" - export const useCurrentUser = () => { // We wouldn't have to useSession() here, but doing so improves perf on initial // load since we can skip the getCurrentUser() request. diff --git a/app/layouts/style.css b/app/layouts/style.css deleted file mode 100644 index e69de29..0000000 diff --git a/app/pages/Fietsen.tsx b/app/pages/Fietsen.tsx deleted file mode 100644 index 8ccd166..0000000 --- a/app/pages/Fietsen.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import React, { Suspense } from "react" -import Layout from "app/layouts/Layout" -import { Head, Link, usePaginatedQuery, useRouter, BlitzPage } from "blitz" - -const ITEMS_PER_PAGE = 100 -const FietsenPage: BlitzPage = () => { - return ( -
- - Fietsen - -
-
-

Hoi, welkom op deze pagina!

-
-
-
- ) -} -FietsenPage.getLayout = (page) => {page} -export default FietsenPage diff --git a/app/pages/index.tsx b/app/pages/index.tsx index 82fa84c..69fa928 100644 --- a/app/pages/index.tsx +++ b/app/pages/index.tsx @@ -1,46 +1,19 @@ import React, { Suspense } from "react" import Layout from "app/layouts/Layout" -import { Head, Link, usePaginatedQuery, useRouter, BlitzPage } from "blitz" +import { Head, BlitzPage } from "blitz" import { useCurrentUser } from "app/hooks/useCurrentUser" import logout from "app/auth/mutations/logout" import { LabeledTextField } from "app/components/LabeledTextField" import { Form, FORM_ERROR } from "app/components/Form" import login from "app/auth/mutations/login" import { LoginInput, LoginInputType } from "app/auth/validations" -const ITEMS_PER_PAGE = 100 - -const loginForm = () => { - return ( -
-
Login
-
-
-
- - -
-
-
- - -
-
-
-
-
- -
-
- ) -} +import { CurrentUser } from "app/pages/CurrentUser" type LoginFormProps = { onSuccess?: () => void + onLogOut?: () => void } const UserInfo = (props: LoginFormProps) => { const currentUser = useCurrentUser() - if (currentUser) { return ( <> @@ -48,14 +21,18 @@ const UserInfo = (props: LoginFormProps) => { className="button small" onClick={async () => { await logout() + if (props.onLogOut) { + props.onLogOut() + } }} > Logout
- User id: {currentUser.id} -
- User role: {currentUser.role} +

+ Hallo {currentUser.email}!, Welkom op de site! Uw UserID is: + {currentUser.id}. Uw UserRole is: {currentUser.role} +

) @@ -68,7 +45,9 @@ const UserInfo = (props: LoginFormProps) => { onSubmit={async (values) => { try { await login({ email: values.email, password: values.password }) - props.onSuccess && props.onSuccess() + if (props.onSuccess) { + props.onSuccess() + } } catch (error) { if (error.name === "AuthenticationError") { return { [FORM_ERROR]: "Sorry, those credentials are invalid" } @@ -94,16 +73,20 @@ const HomePage: BlitzPage = () => { Home + + + + + +

Hoi, welkom op deze pagina!

- - Klik Deze Link! -
) } + HomePage.getLayout = (page) => {page} export default HomePage