-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#186 convert auth into electron setup
- Loading branch information
neil
authored and
neil
committed
Feb 7, 2023
1 parent
680e107
commit 957cba2
Showing
12 changed files
with
159 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { mkdirp } from 'mkdirp'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import { getTeaPath } from './teaDir'; | ||
import type { Session } from '../../src/libs/types'; | ||
import * as v1Client from './v1Client'; | ||
|
||
const sessionFilePath = path.join(getTeaPath(), 'tea.xyz/gui/tmp.dat'); | ||
const sessionFolder = path.join(getTeaPath(), 'tea.xyz/gui'); | ||
|
||
export async function initSessionData() { | ||
fs.readFileSync(sessionFilePath); | ||
|
||
await mkdirp(sessionFolder); | ||
const req = await v1Client.get<{ deviceId: string }>('/auth/registerDevice'); | ||
} | ||
|
||
export async function readSessionData(): Promise<Session> { | ||
try { | ||
const sessionBuffer = await fs.readFileSync(sessionFilePath); | ||
const session = JSON.parse(sessionBuffer.toString()) as Session; | ||
return session; | ||
} catch (error) { | ||
console.error(error); | ||
const req = await v1Client.get<{ deviceId: string }>('/auth/registerDevice'); | ||
const data = { device_id: req.deviceId }; | ||
await writeSessionData(data); | ||
return data; | ||
} | ||
} | ||
|
||
export async function writeSessionData(data: Session) { | ||
try { | ||
await mkdirp(sessionFolder); | ||
await fs.writeFileSync(sessionFilePath, JSON.stringify(data), { | ||
encoding: 'utf-8' | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import axios from 'axios'; | ||
import path from 'path'; | ||
|
||
const base = 'https://api.tea.xyz'; | ||
export async function get<T>(urlPath: string) { | ||
const url = new URL(path.join('v1', urlPath), base).toString(); | ||
// TODO: add headers | ||
const req = await axios.request<T>({ | ||
method: 'GET', | ||
url, | ||
headers: {} | ||
}); | ||
|
||
return req.data; | ||
} | ||
|
||
export default get; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 8 additions & 6 deletions
14
modules/desktop/src/components/TopBar/ProfileNavButton.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.