Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SolidJS-Tailwind] Implement authentication #734

Merged
merged 15 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions solidjs-tailwind/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VITE_API_URL=https://api.starter.dev/api
VITE_GITHUB_URL=https://api.github.com
VITE_BASE_URL=http://localhost:3000
5 changes: 5 additions & 0 deletions solidjs-tailwind/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
node_modules
dist

# env file
.env.development
.env.production
.env.local

# .vscode
.vscode/*
24 changes: 12 additions & 12 deletions solidjs-tailwind/index.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<link rel="shortcut icon" type="image/ico" href="/src/assets/favicon.ico" />
<title>solidjs-tailwindcss starter kit</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="theme-color" content="#000000"/>
<link rel="shortcut icon" type="image/ico" href="/src/assets/favicon.ico"/>
<title>solidjs-tailwindcss starter kit</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>

<script src="/src/index.jsx" type="module"></script>
</body>
<script src="/src/index.jsx" type="module"></script>
</body>
</html>
2 changes: 2 additions & 0 deletions solidjs-tailwind/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"@heroicons/react": "1.0.5"
},
"dependencies": {
"@octokit/rest": "^19.0.5",
"isomorphic-fetch": "^3.0.0",
"solid-heroicons": "^3.1.0",
"solid-js": "1.6.0"
},
Expand Down
167 changes: 161 additions & 6 deletions solidjs-tailwind/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 8 additions & 13 deletions solidjs-tailwind/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { Routes, Route } from '@solidjs/router';
import { Header} from './components/';
import { Home, Counter, ApiExample } from './pages';
import { Route, Routes } from '@solidjs/router';
import { Home, RedirectPage, SigninPage } from './pages';
import ROUTES from './routes';

function App() {
return (
<>
<Header user={{login: 'SDaian'}}/>
<div class="text-center">
<Routes>
<Route component={Home} path="/" />
<Route component={Counter} path="/counter" />
<Route component={ApiExample} path="/api-example" />
</Routes>
</div>
</>
<Routes>
<Route component={Home} path={ROUTES.HOME} />
<Route component={SigninPage} path={ROUTES.SIGNIN} />
<Route component={RedirectPage} path={ROUTES.REDIRECT} />
</Routes>
);
}

Expand Down
11 changes: 11 additions & 0 deletions solidjs-tailwind/src/auth/AuthStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createStore } from 'solid-js/store';

const createAuthStore = () =>
createStore({
token: null,
get isAuthenticated() {
return !!this.token;
},
});

export default createAuthStore;
11 changes: 11 additions & 0 deletions solidjs-tailwind/src/auth/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import createAuthStore from './AuthStore';
import ROUTES from '../routes';
import createPreventUnauthorised from './preventUnauthorised';

const [authStore, setAuth] = createAuthStore();
const preventUnauthorised = createPreventUnauthorised(authStore, ROUTES.SIGNIN);
export const useAuth = () => ({
authStore,
preventUnauthorised,
setAuth,
});
Loading