Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
soerface committed Nov 9, 2024
0 parents commit 98b1d55
Show file tree
Hide file tree
Showing 26 changed files with 908 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

# Sentry Config File
.env.sentry-build-plugin
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react'

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})
```
28 changes: 28 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/fd.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>flipdot apps</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "apps",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"dev-public": "vite --host 0.0.0.0",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@sentry/integrations": "^7.114.0",
"@sentry/react": "^8.36.0",
"@sentry/vite-plugin": "^2.22.6",
"oidc-client-ts": "^3.1.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.27.0"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react-swc": "^3.5.0",
"eslint": "^9.13.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.14",
"globals": "^15.11.0",
"typescript": "~5.6.2",
"typescript-eslint": "^8.11.0",
"vite": "^5.4.10"
}
}
12 changes: 12 additions & 0 deletions public/fd.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
body {
margin: 0;
/*display: flex;*/
/*flex-direction: column;*/
/*justify-content: flex-start;*/
/*place-items: center;*/
/*min-width: 320px;*/
/*min-height: 100vh;*/
}

#root {
margin: 0;
display: flex;
flex-direction: column;
place-items: flex-start;
/*min-width: 320px;*/
/*min-height: 100vh;*/
}

#content {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

/*.xlogo:hover {*/
/* filter: drop-shadow(0 0 2em #f5c600);*/
/*}*/

@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;
}
52 changes: 52 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import flipdotLogo from './assets/flipdot.svg'
import './App.css'
// import { Navigate, useLocation, useNavigate } from "react-router-dom";
import Login from "./Login.tsx";
import {AuthProvider, useAuth} from "./AuthContext.tsx";
import React from "react";
import {Route, Routes} from "react-router-dom";
import Home from "./Home.tsx";
import RequireAuth from "./RequireAuth.tsx";
import LoginCallback from "./LoginCallback.tsx";
import NavBar from "./NavBar.tsx";


function App() {

return <AuthProvider>
<NavBar/>
<div id="content">
<Routes>
<Route element={<RequireAuth/>}>
<Route path="/" element={<Home/>}/>
</Route>
<Route path="/login" element={<Login/>}/>
<Route path="/login/callback" element={<LoginCallback/>}/>
</Routes>
</div>
</AuthProvider>

// const auth = useAuth();
// // let navigate = useNavigate();
//
// if (!auth.user) {
// return <Login />
// }
//
//
// return (
// <>
// <div>
// <img src={flipdotLogo} className="logo" alt="flipdot logo" />
// </div>
// <h1>flipdot app dashboard</h1>
// <div className="card">
// <p>
// TODO: List of apps go here
// </p>
// </div>
// </>
// )
}

export default App
56 changes: 56 additions & 0 deletions src/AuthContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import './App.css'
import {User} from 'oidc-client-ts'
// import { Navigate, useLocation, useNavigate } from "react-router-dom";
import {createContext, useContext, useState} from "react";
import AuthService from "./AuthService.ts";

interface AuthContextType {
user: null | User;
login: () => void;
logout: () => void;
loginCallback: () => Promise<null | User>;
}

const AuthContext = createContext<AuthContextType>({
user: null,
login: () => {
console.error("login not implemented. Did you forget to wrap your app in an AuthProvider?");
},
logout: () => {
console.error("logout not implemented. Did you forget to wrap your app in an AuthProvider?");
},
loginCallback: async () => {
console.error("loginCallback not implemented. Did you forget to wrap your app in an AuthProvider?");
return null;
}
});

const useAuth = () => useContext(AuthContext);

function AuthProvider({children}: { children: React.ReactNode }) {
const [user, setUser] = useState<User | null>(
JSON.parse(
sessionStorage.getItem("session") || "null"
) || undefined
);

const authService = new AuthService();

const loginCallback = async () => {
const authedUser = await authService.loginCallback();
setUser(authedUser);
return authedUser;
};

const login = () => authService.login();
const logout = async () => {
await authService.logout();
setUser(null);
}

const value = {user, login, logout, loginCallback};

return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
}

export {useAuth, AuthProvider};
33 changes: 33 additions & 0 deletions src/AuthService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import {UserManager} from "oidc-client-ts";

export default class AuthService {
private userManager: UserManager;

constructor() {
this.userManager = new UserManager({
authority: "https://login.flipdot.org/realms/flipdot",
client_id: "flipdot-app-dashboard",
redirect_uri: window.location.origin + "/login/callback",
response_type: "code",
})
}

getUser() {
return this.userManager.getUser();
}

login() {
return this.userManager.signinRedirect();
}

loginCallback() {
return this.userManager.signinRedirectCallback();
}

logout() {
// only logout in this application, not on the oidc server
return this.userManager.revokeTokens().then(() => {
return this.userManager.removeUser();
});
}
}
26 changes: 26 additions & 0 deletions src/Home.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import flipdotLogo from './assets/flipdot.svg'
import './App.css'
// import { Navigate, useLocation, useNavigate } from "react-router-dom";
import React from "react";


function Home() {

// const auth = useAuth();

return (
<>
<div>
<img src={flipdotLogo} className="logo" alt="flipdot logo"/>
</div>
<h1>flipdot app dashboard</h1>
<div className="card">
<p>
TODO: List of apps go here
</p>
</div>
</>
)
}

export default Home
Loading

0 comments on commit 98b1d55

Please sign in to comment.