Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 5d191a6

Browse files
committed
Framework for clientside api calls
1 parent 9e01911 commit 5d191a6

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

client/src/api/challenges.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import preactLocalStorage from 'preact-localstorage'
2+
3+
export const getChallenges = () => {
4+
const auth = preactLocalStorage.get('token', 'AUTH_TOKEN_HERE')
5+
console.log(auth)
6+
7+
return []
8+
}

client/src/api/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { route } from 'preact-router'
2+
import preactLocalStorage from 'preact-localstorage'
3+
4+
const badToken = () => {
5+
preactLocalStorage.get('token', 'AUTH_TOKEN_HERE')
6+
route('/login')
7+
}
8+
9+
export const request = (method, endpoint, data) => {
10+
// fetch endpoint with HTTP method, data as body
11+
12+
badToken()
13+
}

client/src/api/login.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import preactLocalStorage from 'preact-localstorage'
2+
import { route } from 'preact-router'
3+
4+
export const login = teamToken => {
5+
preactLocalStorage.set('token', 'AUTH_TOKEN_HERE')
6+
route('/challenges')
7+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"nyc": "^15.0.0",
4040
"preact": "^10.3.1",
4141
"preact-cli": "^2.2.1",
42+
"preact-localstorage": "^1.0.2",
4243
"preact-router": "^3.2.1",
4344
"promise-polyfill": "^8.1.3",
4445
"regenerator-runtime": "^0.13.3",

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6595,6 +6595,11 @@ preact-context@^1.1.3:
65956595
version "1.1.4"
65966596
resolved "https://registry.yarnpkg.com/preact-context/-/preact-context-1.1.4.tgz#866ebd35bef5788f73fc453f06f01b03ddf8f4ff"
65976597

6598+
preact-localstorage@^1.0.2:
6599+
version "1.0.2"
6600+
resolved "https://registry.yarnpkg.com/preact-localstorage/-/preact-localstorage-1.0.2.tgz#8f633dbec38e8b9222f86381275afc61b0fa3fe7"
6601+
integrity sha512-F490p/txuivO3BuFZhMYZxP14sbjqm7n5R5IeM5EP6WcO83JCVE8V1q3+Q9POlIW2y1Ql/dzXHJyDiNqKeMuqA==
6602+
65986603
preact-render-to-string@^3.6.0, preact-render-to-string@^3.8.2:
65996604
version "3.8.2"
66006605
resolved "https://registry.yarnpkg.com/preact-render-to-string/-/preact-render-to-string-3.8.2.tgz#bd72964d705a57da3a9e72098acaa073dd3ceff9"

0 commit comments

Comments
 (0)