clenaup cookie bullshit after api-deux pr merged (#2151)

* clenaup cookie bullshit after api-deux pr merged

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* check empty

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2024-04-18 17:18:03 -07:00
committed by GitHub
parent f909ea7af5
commit 69d34c5318
3 changed files with 6 additions and 38 deletions

View File

@ -41,7 +41,6 @@
"fuse.js": "^7.0.0", "fuse.js": "^7.0.0",
"html2canvas-pro": "^1.4.3", "html2canvas-pro": "^1.4.3",
"http-server": "^14.1.1", "http-server": "^14.1.1",
"js-cookie": "^3.0.5",
"json-rpc-2.0": "^1.6.0", "json-rpc-2.0": "^1.6.0",
"jszip": "^3.10.1", "jszip": "^3.10.1",
"node-fetch": "^3.3.2", "node-fetch": "^3.3.2",
@ -123,7 +122,6 @@
"@tauri-apps/cli": "^2.0.0-beta.13", "@tauri-apps/cli": "^2.0.0-beta.13",
"@types/crypto-js": "^4.2.2", "@types/crypto-js": "^4.2.2",
"@types/debounce-promise": "^3.1.9", "@types/debounce-promise": "^3.1.9",
"@types/js-cookie": "^3.0.6",
"@types/pixelmatch": "^5.2.6", "@types/pixelmatch": "^5.2.6",
"@types/pngjs": "^6.0.4", "@types/pngjs": "^6.0.4",
"@types/react-modal": "^3.16.3", "@types/react-modal": "^3.16.3",

View File

@ -4,7 +4,6 @@ import withBaseURL from '../lib/withBaseURL'
import { isTauri } from 'lib/isTauri' import { isTauri } from 'lib/isTauri'
import { invoke } from '@tauri-apps/api/core' import { invoke } from '@tauri-apps/api/core'
import { VITE_KC_API_BASE_URL } from 'env' import { VITE_KC_API_BASE_URL } from 'env'
import Cookies from 'js-cookie'
const SKIP_AUTH = const SKIP_AUTH =
import.meta.env.VITE_KC_SKIP_AUTH === 'true' && import.meta.env.DEV import.meta.env.VITE_KC_SKIP_AUTH === 'true' && import.meta.env.DEV
@ -135,35 +134,18 @@ async function getUser(context: UserContext) {
hostname: VITE_KC_API_BASE_URL, hostname: VITE_KC_API_BASE_URL,
}).catch((err) => console.error('error from Tauri getUser', err)) }).catch((err) => console.error('error from Tauri getUser', err))
const tokenPromise = !isTauri()
? fetch(withBaseURL('/user/api-tokens?limit=1'), {
method: 'GET',
credentials: 'include',
headers,
})
.then(async (res) => {
const result: Models['ApiTokenResultsPage_type'] = await res.json()
return result.items[0].token
})
.catch((err) => console.error('error from Browser getUser', err))
: context.token
const user = await userPromise const user = await userPromise
const token = await tokenPromise
if ('error_code' in user) throw new Error(user.message) if ('error_code' in user) throw new Error(user.message)
console.log('context.token "', context.token, '"')
console.log('cookie "', getCookie(COOKIE_NAME), '"')
console.log(
'localStorage.getItem(TOKEN_PERSIST_KEY) "',
localStorage?.getItem(TOKEN_PERSIST_KEY),
'"'
)
return { return {
user, user,
token, token:
context.token && context.token !== ''
? context.token
: getCookie(COOKIE_NAME) ||
localStorage?.getItem(TOKEN_PERSIST_KEY) ||
'',
} }
} }
@ -172,8 +154,6 @@ function getCookie(cname: string): string | null {
return null return null
} }
console.log('cookies', Cookies.get())
let name = cname + '=' let name = cname + '='
let decodedCookie = decodeURIComponent(document.cookie) let decodedCookie = decodeURIComponent(document.cookie)
let ca = decodedCookie.split(';') let ca = decodedCookie.split(';')

View File

@ -2417,11 +2417,6 @@
expect "^29.0.0" expect "^29.0.0"
pretty-format "^29.0.0" pretty-format "^29.0.0"
"@types/js-cookie@^3.0.6":
version "3.0.6"
resolved "https://registry.yarnpkg.com/@types/js-cookie/-/js-cookie-3.0.6.tgz#a04ca19e877687bd449f5ad37d33b104b71fdf95"
integrity sha512-wkw9yd1kEXOPnvEeEV1Go1MmxtBJL0RR79aOTAApecWFVu7w0NNXNqhcWgvw2YgZDYadliXkl14pa3WXw5jlCQ==
"@types/json-schema@*", "@types/json-schema@^7.0.9": "@types/json-schema@*", "@types/json-schema@^7.0.9":
version "7.0.12" version "7.0.12"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.12.tgz#d70faba7039d5fca54c83c7dbab41051d2b6f6cb" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.12.tgz#d70faba7039d5fca54c83c7dbab41051d2b6f6cb"
@ -6237,11 +6232,6 @@ joi@^17.11.0:
"@sideway/formula" "^3.0.1" "@sideway/formula" "^3.0.1"
"@sideway/pinpoint" "^2.0.0" "@sideway/pinpoint" "^2.0.0"
js-cookie@^3.0.5:
version "3.0.5"
resolved "https://registry.yarnpkg.com/js-cookie/-/js-cookie-3.0.5.tgz#0b7e2fd0c01552c58ba86e0841f94dc2557dcdbc"
integrity sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==
"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0: "js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
version "4.0.0" version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"