mirror of
https://github.com/versia-pub/frontend.git
synced 2026-03-13 11:39:16 +01:00
feat: ✨ Make PWA installable with icons and screenshots
This commit is contained in:
parent
60cbe129bb
commit
d0b82e822d
122 changed files with 552 additions and 48 deletions
48
utils/auth.ts
Normal file
48
utils/auth.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import { nanoid } from "nanoid";
|
||||
|
||||
export const signInWithCode = (code: string, appData: ApplicationData) => {
|
||||
const identity = useCurrentIdentity();
|
||||
const identities = useIdentities();
|
||||
const client = useClient();
|
||||
|
||||
client.value
|
||||
?.fetchAccessToken(
|
||||
appData.client_id,
|
||||
appData.client_secret,
|
||||
code,
|
||||
new URL("/", useRequestURL().origin).toString(),
|
||||
)
|
||||
.then(async (res) => {
|
||||
const tempClient = useClient(res.data).value;
|
||||
|
||||
const [accountOutput, instanceOutput] = await Promise.all([
|
||||
tempClient.verifyAccountCredentials(),
|
||||
tempClient.getInstance(),
|
||||
]);
|
||||
|
||||
// Get account data
|
||||
if (
|
||||
!identities.value.find(
|
||||
(i) => i.account.id === accountOutput.data.id,
|
||||
)
|
||||
)
|
||||
identity.value = {
|
||||
id: nanoid(),
|
||||
tokens: res.data,
|
||||
account: accountOutput.data,
|
||||
instance: instanceOutput.data,
|
||||
permissions: [],
|
||||
emojis: [],
|
||||
};
|
||||
|
||||
// Remove code from URL
|
||||
window.history.replaceState(
|
||||
{},
|
||||
document.title,
|
||||
window.location.pathname,
|
||||
);
|
||||
|
||||
// Redirect to home
|
||||
window.location.pathname = "/";
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue