diff --git a/index.html b/index.html
index e4b78ea..303aab1 100644
--- a/index.html
+++ b/index.html
@@ -2,9 +2,8 @@
-
- Vite + React + TS
+ Kneipolympics
diff --git a/package-lock.json b/package-lock.json
index 809cf8b..fd331b0 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -8,6 +8,7 @@
"name": "kneipolympics",
"version": "0.0.0",
"dependencies": {
+ "appwrite": "^16.0.2",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
@@ -1663,6 +1664,12 @@
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
+ "node_modules/appwrite": {
+ "version": "16.0.2",
+ "resolved": "https://registry.npmjs.org/appwrite/-/appwrite-16.0.2.tgz",
+ "integrity": "sha512-sCMVOe9wdB8OneIz6LtoYhp797GEXoudAdygNZgezPiybGOlMPcQ8kP1c/FW1eES0ledaqgaZ0PHb+LwZia8pw==",
+ "license": "BSD-3-Clause"
+ },
"node_modules/argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
diff --git a/package.json b/package.json
index fed473f..850cb0e 100644
--- a/package.json
+++ b/package.json
@@ -10,6 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
+ "appwrite": "^16.0.2",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
diff --git a/public/vite.svg b/public/vite.svg
deleted file mode 100644
index e7b8dfb..0000000
--- a/public/vite.svg
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/src/App.css b/src/App.css
index b9d355d..e69de29 100644
--- a/src/App.css
+++ b/src/App.css
@@ -1,42 +0,0 @@
-#root {
- max-width: 1280px;
- margin: 0 auto;
- padding: 2rem;
- text-align: center;
-}
-
-.logo {
- height: 6em;
- padding: 1.5em;
- will-change: filter;
- transition: filter 300ms;
-}
-.logo:hover {
- filter: drop-shadow(0 0 2em #646cffaa);
-}
-.logo.react:hover {
- filter: drop-shadow(0 0 2em #61dafbaa);
-}
-
-@keyframes logo-spin {
- from {
- transform: rotate(0deg);
- }
- to {
- transform: rotate(360deg);
- }
-}
-
-@media (prefers-reduced-motion: no-preference) {
- a:nth-of-type(2) .logo {
- animation: logo-spin infinite 20s linear;
- }
-}
-
-.card {
- padding: 2em;
-}
-
-.read-the-docs {
- color: #888;
-}
diff --git a/src/App.tsx b/src/App.tsx
index 7f0b6bc..0713448 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,33 +1,14 @@
-import { useState } from "react";
-import reactLogo from "./assets/react.svg";
-import viteLogo from "/vite.svg";
import "./App.css";
-export function App() {
- const [count, setCount] = useState(0);
+import { AppwriteContextProvider } from "./contexts/appwrite";
+import { AuthContextProvider } from "./contexts/auth";
+export function App() {
return (
<>
-
- Vite + React
-
-
-
- Edit src/App.tsx
and save to test HMR
-
-
-
- Click on the Vite and React logos to learn more
-
+
+
+
>
);
}
diff --git a/src/assets/react.svg b/src/assets/react.svg
deleted file mode 100644
index 6c87de9..0000000
--- a/src/assets/react.svg
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/src/contexts/appwrite.tsx b/src/contexts/appwrite.tsx
new file mode 100644
index 0000000..e4069bb
--- /dev/null
+++ b/src/contexts/appwrite.tsx
@@ -0,0 +1,27 @@
+import { Client } from "appwrite";
+import { createContext, PropsWithChildren } from "react";
+
+export type AppwriteContextValue = {
+ client: Client;
+};
+
+export const AppwriteContext = createContext(
+ {} as AppwriteContextValue,
+);
+
+type Props = PropsWithChildren;
+
+export function AppwriteContextProvider({ children }: Props) {
+ const client = new Client();
+ client.setProject("67257b8d001f6f36d0be");
+
+ const value = {
+ client,
+ };
+
+ return (
+
+ {children}
+
+ );
+}
diff --git a/src/contexts/auth.tsx b/src/contexts/auth.tsx
new file mode 100644
index 0000000..a16e419
--- /dev/null
+++ b/src/contexts/auth.tsx
@@ -0,0 +1,47 @@
+import { createContext, PropsWithChildren, useState } from "react";
+import { useAppwrite } from "../hooks/useAppwrite";
+import { Account, Models } from "appwrite";
+
+export type AuthContextValue = {
+ session?: Models.Session;
+ login(username: string, password: string): Promise;
+ logout(): Promise;
+};
+
+export const AuthContext = createContext({} as AuthContextValue);
+
+export function AuthContextProvider({ children }: PropsWithChildren) {
+ const { client } = useAppwrite();
+ const account = new Account(client);
+
+ const [session, setSession] = useState();
+
+ async function login(username: string, password: string): Promise {
+ try {
+ const session = await account.createEmailPasswordSession(
+ username,
+ password,
+ );
+
+ setSession(session);
+ } catch (e) {
+ console.error(e);
+ }
+ }
+
+ async function logout(): Promise {
+ try {
+ await account.deleteSession("current");
+ } catch (e) {
+ console.error(e);
+ }
+ }
+
+ const value = {
+ login,
+ session,
+ logout,
+ };
+
+ return {children};
+}
diff --git a/src/hooks/useAppwrite.ts b/src/hooks/useAppwrite.ts
new file mode 100644
index 0000000..97e57ce
--- /dev/null
+++ b/src/hooks/useAppwrite.ts
@@ -0,0 +1,6 @@
+import { useContext } from "react";
+import { AppwriteContext } from "../contexts/appwrite";
+
+export function useAppwrite() {
+ return useContext(AppwriteContext);
+}
diff --git a/src/index.css b/src/index.css
index 6119ad9..e69de29 100644
--- a/src/index.css
+++ b/src/index.css
@@ -1,68 +0,0 @@
-:root {
- font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
- line-height: 1.5;
- font-weight: 400;
-
- color-scheme: light dark;
- color: rgba(255, 255, 255, 0.87);
- background-color: #242424;
-
- font-synthesis: none;
- text-rendering: optimizeLegibility;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
-}
-
-a {
- font-weight: 500;
- color: #646cff;
- text-decoration: inherit;
-}
-a:hover {
- color: #535bf2;
-}
-
-body {
- margin: 0;
- display: flex;
- place-items: center;
- min-width: 320px;
- min-height: 100vh;
-}
-
-h1 {
- font-size: 3.2em;
- line-height: 1.1;
-}
-
-button {
- border-radius: 8px;
- border: 1px solid transparent;
- padding: 0.6em 1.2em;
- font-size: 1em;
- font-weight: 500;
- font-family: inherit;
- background-color: #1a1a1a;
- cursor: pointer;
- transition: border-color 0.25s;
-}
-button:hover {
- border-color: #646cff;
-}
-button:focus,
-button:focus-visible {
- outline: 4px auto -webkit-focus-ring-color;
-}
-
-@media (prefers-color-scheme: light) {
- :root {
- color: #213547;
- background-color: #ffffff;
- }
- a:hover {
- color: #747bff;
- }
- button {
- background-color: #f9f9f9;
- }
-}