Send authorization to server for version list
This commit is contained in:
4 files changed
+96
-35
No files matched your search
@@ -2,13 +2,15 @@
|
|||||||
|
|
||||||
import { verifySignature } from '@/lib/util'
|
import { verifySignature } from '@/lib/util'
|
||||||
import { useGlobal } from '@/providers/GlobalProvider'
|
import { useGlobal } from '@/providers/GlobalProvider'
|
||||||
|
import { app } from '@tauri-apps/api'
|
||||||
import { message } from '@tauri-apps/plugin-dialog'
|
import { message } from '@tauri-apps/plugin-dialog'
|
||||||
import { fetch } from '@tauri-apps/plugin-http'
|
import { fetch } from '@tauri-apps/plugin-http'
|
||||||
import { openUrl } from '@tauri-apps/plugin-opener'
|
import { openUrl } from '@tauri-apps/plugin-opener'
|
||||||
|
import { arch, platform } from '@tauri-apps/plugin-os'
|
||||||
import { Dispatch, SetStateAction, useState } from 'react'
|
import { Dispatch, SetStateAction, useState } from 'react'
|
||||||
|
|
||||||
function AccountLoggedOut () {
|
function AccountLoggedOut () {
|
||||||
const { account } = useGlobal()
|
const { account, setServerVersionList } = useGlobal()
|
||||||
const [username, setUsername] = useState<string>('')
|
const [username, setUsername] = useState<string>('')
|
||||||
const [password, setPassword] = useState<string>('')
|
const [password, setPassword] = useState<string>('')
|
||||||
|
|
||||||
@@ -44,12 +46,27 @@ function AccountLoggedOut () {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
if (data.data.session)
|
const response2 = await fetch(
|
||||||
|
'https://games.lncvrt.xyz/api/launcher/versions',
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Requester: 'LncvrtGamesLauncherClient',
|
||||||
|
ClientVersion: await app.getVersion(),
|
||||||
|
ClientPlatform: platform() + '-' + arch(),
|
||||||
|
Authorization: data.data.session
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
const signature2 = response2.headers.get('x-signature') ?? ''
|
||||||
|
const data2 = await response2.json()
|
||||||
|
if (await verifySignature(JSON.stringify(data2), signature2)) {
|
||||||
|
setServerVersionList(data2)
|
||||||
|
}
|
||||||
|
|
||||||
await account?.set('session', data.data.session)
|
await account?.set('session', data.data.session)
|
||||||
if (data.data.username)
|
|
||||||
await account?.set('name', data.data.username)
|
await account?.set('name', data.data.username)
|
||||||
if (data.data.id) await account?.set('id', data.data.id)
|
await account?.set('id', data.data.id)
|
||||||
if (data.data.admin) await account?.set('admin', data.data.admin)
|
await account?.set('admin', data.data.admin)
|
||||||
} else {
|
} else {
|
||||||
await message(data.message || 'n/a', {
|
await message(data.message || 'n/a', {
|
||||||
title: 'Failed to login',
|
title: 'Failed to login',
|
||||||
@@ -161,7 +178,7 @@ function AccountChangeUsername ({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
if (data.data) await account?.set('session', data.data)
|
await account?.set('session', data.data)
|
||||||
await account?.set('name', newUsername)
|
await account?.set('name', newUsername)
|
||||||
setChangingUsername(false)
|
setChangingUsername(false)
|
||||||
} else {
|
} else {
|
||||||
@@ -203,7 +220,7 @@ function AccountChangePassword ({
|
|||||||
}: {
|
}: {
|
||||||
setChangingPassword: Dispatch<SetStateAction<boolean>>
|
setChangingPassword: Dispatch<SetStateAction<boolean>>
|
||||||
}) {
|
}) {
|
||||||
const { account, accountSession } = useGlobal()
|
const { account, accountSession, setServerVersionList } = useGlobal()
|
||||||
|
|
||||||
const [newPassword, setNewPassword] = useState<string>('')
|
const [newPassword, setNewPassword] = useState<string>('')
|
||||||
const [retypeNewPassword, setRetypeNewPassword] = useState<string>('')
|
const [retypeNewPassword, setRetypeNewPassword] = useState<string>('')
|
||||||
@@ -218,7 +235,10 @@ function AccountChangePassword ({
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
if (newPassword !== retypeNewPassword) {
|
if (newPassword !== retypeNewPassword) {
|
||||||
alert('Passwords must match')
|
message('Passwords must match', {
|
||||||
|
title: "Passwords don't match!",
|
||||||
|
kind: 'error'
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +265,24 @@ function AccountChangePassword ({
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
if (data.data) await account?.set('session', data.data)
|
const response2 = await fetch(
|
||||||
|
'https://games.lncvrt.xyz/api/launcher/versions',
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Requester: 'LncvrtGamesLauncherClient',
|
||||||
|
ClientVersion: await app.getVersion(),
|
||||||
|
ClientPlatform: platform() + '-' + arch(),
|
||||||
|
Authorization: data.data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
const signature2 = response2.headers.get('x-signature') ?? ''
|
||||||
|
const data2 = await response2.json()
|
||||||
|
if (await verifySignature(JSON.stringify(data2), signature2)) {
|
||||||
|
setServerVersionList(data2)
|
||||||
|
}
|
||||||
|
|
||||||
|
await account?.set('session', data.data)
|
||||||
setChangingPassword(false)
|
setChangingPassword(false)
|
||||||
} else {
|
} else {
|
||||||
await message(data.message || 'n/a', {
|
await message(data.message || 'n/a', {
|
||||||
@@ -294,7 +331,7 @@ function AccountChangePassword ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function AccountLoggedIn () {
|
function AccountLoggedIn () {
|
||||||
const { account, accountName } = useGlobal()
|
const { account, accountName, setServerVersionList } = useGlobal()
|
||||||
const [changingUsername, setChangingUsername] = useState<boolean>(false)
|
const [changingUsername, setChangingUsername] = useState<boolean>(false)
|
||||||
const [changingPassword, setChangingPassword] = useState<boolean>(false)
|
const [changingPassword, setChangingPassword] = useState<boolean>(false)
|
||||||
|
|
||||||
@@ -323,7 +360,26 @@ function AccountLoggedIn () {
|
|||||||
Change password
|
Change password
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={async () => await account?.clear()}
|
onClick={async () => {
|
||||||
|
const response = await fetch(
|
||||||
|
'https://games.lncvrt.xyz/api/launcher/versions',
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Requester: 'LncvrtGamesLauncherClient',
|
||||||
|
ClientVersion: await app.getVersion(),
|
||||||
|
ClientPlatform: platform() + '-' + arch(),
|
||||||
|
Authorization: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
const signature = response.headers.get('x-signature') ?? ''
|
||||||
|
const data = await response.json()
|
||||||
|
if (await verifySignature(JSON.stringify(data), signature)) {
|
||||||
|
setServerVersionList(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
await account?.clear()
|
||||||
|
}}
|
||||||
className='button btntheme1'
|
className='button btntheme1'
|
||||||
>
|
>
|
||||||
Logout
|
Logout
|
||||||
|
|||||||
+27
-23
@@ -593,29 +593,6 @@ export default function RootLayout ({
|
|||||||
setPlatformName(platform())
|
setPlatformName(platform())
|
||||||
const client = await app.getVersion()
|
const client = await app.getVersion()
|
||||||
setVersion(client)
|
setVersion(client)
|
||||||
try {
|
|
||||||
const response = await fetch(
|
|
||||||
'https://games.lncvrt.xyz/api/launcher/versions',
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
Requester: 'LncvrtGamesLauncherClient',
|
|
||||||
ClientVersion: await app.getVersion(),
|
|
||||||
ClientPlatform: platform() + '-' + arch()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
const signature = response.headers.get('x-signature') ?? ''
|
|
||||||
const data = await response.json()
|
|
||||||
if (await verifySignature(JSON.stringify(data), signature)) {
|
|
||||||
setServerVersionList(data)
|
|
||||||
} else {
|
|
||||||
setLoadingText('Failed to download versions list.')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
setLoadingText('Failed to download versions list.')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const legacyOptions = {
|
const legacyOptions = {
|
||||||
baseDir: BaseDirectory.AppLocalData
|
baseDir: BaseDirectory.AppLocalData
|
||||||
}
|
}
|
||||||
@@ -733,6 +710,32 @@ export default function RootLayout ({
|
|||||||
setSettings(settingsLocal)
|
setSettings(settingsLocal)
|
||||||
setVersions(versionsLocal)
|
setVersions(versionsLocal)
|
||||||
setAccount(accountLocal)
|
setAccount(accountLocal)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
'https://games.lncvrt.xyz/api/launcher/versions',
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Requester: 'LncvrtGamesLauncherClient',
|
||||||
|
ClientVersion: await app.getVersion(),
|
||||||
|
ClientPlatform: platform() + '-' + arch(),
|
||||||
|
Authorization: (await accountLocal.get('session')) ?? ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
const signature = response.headers.get('x-signature') ?? ''
|
||||||
|
const data = await response.json()
|
||||||
|
if (await verifySignature(JSON.stringify(data), signature)) {
|
||||||
|
setServerVersionList(data)
|
||||||
|
} else {
|
||||||
|
setLoadingText('Failed to download versions list.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
setLoadingText('Failed to download versions list.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
|
||||||
if (!(await isPermissionGranted())) {
|
if (!(await isPermissionGranted())) {
|
||||||
@@ -850,6 +853,7 @@ export default function RootLayout ({
|
|||||||
<GlobalProvider
|
<GlobalProvider
|
||||||
value={{
|
value={{
|
||||||
serverVersionList,
|
serverVersionList,
|
||||||
|
setServerVersionList,
|
||||||
selectedVersionList,
|
selectedVersionList,
|
||||||
setSelectedVersionList,
|
setSelectedVersionList,
|
||||||
downloadProgress,
|
downloadProgress,
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ export default function Sidebar () {
|
|||||||
className={
|
className={
|
||||||
'flex items-center h-10 w-60 ' +
|
'flex items-center h-10 w-60 ' +
|
||||||
(platform() == 'windows' ? 'pl-1 pt-1' : 'pl-2 pt-2') +
|
(platform() == 'windows' ? 'pl-1 pt-1' : 'pl-2 pt-2') +
|
||||||
(platform() == 'macos' ? ' mt-7' : '')
|
(platform() == 'macos' ? ' mt-6' : '')
|
||||||
}
|
}
|
||||||
onMouseDown={e => {
|
onMouseDown={e => {
|
||||||
if (platform() != 'macos') return
|
if (platform() != 'macos') return
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import { GameVersion } from '@/types/GameVersion'
|
|||||||
|
|
||||||
type GlobalCtxType = {
|
type GlobalCtxType = {
|
||||||
serverVersionList: ServerVersionsResponse | null
|
serverVersionList: ServerVersionsResponse | null
|
||||||
|
setServerVersionList: Dispatch<SetStateAction<ServerVersionsResponse | null>>
|
||||||
selectedVersionList: string[]
|
selectedVersionList: string[]
|
||||||
setSelectedVersionList: (value: SetStateAction<string[]>) => void
|
setSelectedVersionList: (value: SetStateAction<string[]>) => void
|
||||||
downloadProgress: DownloadProgress[]
|
downloadProgress: DownloadProgress[]
|
||||||
|
|||||||
Reference in new issue
Block a user