+ {user ? (
+ <>
+
{user.username}
+
+ >
+ ) : (
+
+ )}
diff --git a/src/components/Header/Header.module.scss b/src/components/Header/Header.module.scss
index 01dfc40..a80cf5b 100644
--- a/src/components/Header/Header.module.scss
+++ b/src/components/Header/Header.module.scss
@@ -17,8 +17,28 @@ button {
border: none;
}
+.actions {
+ display: flex;
+ align-items: center;
+}
+
+.username {
+ font-size: 0.9rem;
+ font-weight: 600;
+ color: var(--color-text-primary);
+ max-width: 100px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
@media screen and (max-width: 480px) {
h1 {
font-size: 2rem;
}
+
+ .username {
+ max-width: 60px;
+ font-size: 0.8rem;
+ }
}
diff --git a/src/components/LoginModal/LoginModal.jsx b/src/components/LoginModal/LoginModal.jsx
new file mode 100644
index 0000000..7f51c13
--- /dev/null
+++ b/src/components/LoginModal/LoginModal.jsx
@@ -0,0 +1,71 @@
+import { useState } from 'react';
+import Modal from 'components/Modal';
+import { useAuth } from 'context/AuthContext';
+import styles from './LoginModal.module.scss';
+
+const LoginModal = ({ isOpen, onClose }) => {
+ const { login } = useAuth();
+ const [username, setUsername] = useState('');
+ const [password, setPassword] = useState('');
+ const [error, setError] = useState('');
+
+ const handleSubmit = e => {
+ e.preventDefault();
+ setError('');
+
+ if (!username.trim()) {
+ setError('Please enter a username');
+ return;
+ }
+ if (!password.trim()) {
+ setError('Please enter a password');
+ return;
+ }
+
+ login(username.trim());
+ setUsername('');
+ setPassword('');
+ onClose();
+ };
+
+ return (
+
+
+
+ );
+};
+
+export default LoginModal;
diff --git a/src/components/LoginModal/LoginModal.module.scss b/src/components/LoginModal/LoginModal.module.scss
new file mode 100644
index 0000000..119e1a7
--- /dev/null
+++ b/src/components/LoginModal/LoginModal.module.scss
@@ -0,0 +1,63 @@
+.form {
+ display: flex;
+ flex-direction: column;
+ gap: 1rem;
+ padding: 0.5rem 1rem 1rem;
+}
+
+.field {
+ display: flex;
+ flex-direction: column;
+ text-align: left;
+}
+
+.label {
+ font-size: 0.85rem;
+ font-weight: 500;
+ margin-bottom: 0.3rem;
+ color: var(--color-text-secondary);
+}
+
+.input {
+ padding: 0.6rem 0.8rem;
+ border: 2px solid var(--color-cell);
+ border-radius: 6px;
+ font-size: 1rem;
+ font-family: inherit;
+ background: var(--color-background);
+ color: var(--color-text-primary);
+ outline: none;
+ transition: border-color 0.2s;
+
+ &:focus {
+ border-color: var(--color-correct);
+ }
+
+ &::placeholder {
+ color: var(--color-text-secondary);
+ opacity: 0.6;
+ }
+}
+
+.error {
+ color: var(--color-alert-error);
+ font-size: 0.85rem;
+ margin: 0;
+}
+
+.submit {
+ padding: 0.7rem;
+ border: none;
+ border-radius: 6px;
+ background: var(--color-correct);
+ color: #fff;
+ font-size: 1rem;
+ font-weight: 600;
+ font-family: inherit;
+ cursor: pointer;
+ transition: opacity 0.2s;
+
+ &:hover {
+ opacity: 0.9;
+ }
+}
diff --git a/src/components/LoginModal/index.js b/src/components/LoginModal/index.js
new file mode 100644
index 0000000..2c55498
--- /dev/null
+++ b/src/components/LoginModal/index.js
@@ -0,0 +1 @@
+export { default } from './LoginModal';
diff --git a/src/context/AuthContext.js b/src/context/AuthContext.js
new file mode 100644
index 0000000..fb901ac
--- /dev/null
+++ b/src/context/AuthContext.js
@@ -0,0 +1,24 @@
+import { createContext, useContext } from 'react';
+import useLocalStorage from 'hooks/useLocalStorage';
+
+export const AuthContext = createContext();
+
+export const AuthProvider = ({ children }) => {
+ const [user, setUser] = useLocalStorage('wordleUser', null);
+
+ const login = username => {
+ setUser({ username });
+ };
+
+ const logout = () => {
+ setUser(null);
+ };
+
+ return (
+
+ {children}
+
+ );
+};
+
+export const useAuth = () => useContext(AuthContext);
diff --git a/src/index.js b/src/index.js
index 65c2fdf..059ac0b 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,14 +1,17 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { AlertProvider } from 'context/AlertContext';
+import { AuthProvider } from 'context/AuthContext';
import App from './App';
import reportWebVitals from './reportWebVitals';
ReactDOM.render(
-
-
-
+
+
+
+
+
,
document.getElementById('root')
);