Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/kick - Auth + Linking #1073

Merged
merged 4 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/site/kick.com/KickSite.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ document.body.setAttribute("seventv-kick", "true");

const cookies = useCookies();
const auth = cookies.get("XSRF-TOKEN");
const sessionToken = cookies.get("session_token");

const user = auth ? await useUserdata(auth) : null;
const user = auth ? await useUserdata(auth, sessionToken) : null;

if (user) {
const updateIdentity = (data: typeof user) => {
Expand All @@ -58,6 +59,8 @@ if (user) {
actor.setPlatformUserID("KICK", data.id.toString());
};

//TODO: subscribe for allowing new login

updateIdentity(user);
}

Expand Down
6 changes: 5 additions & 1 deletion src/site/kick.com/composable/useUserdata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export async function useUserdata(auth: string): Promise<{
export async function useUserdata(
auth: string,
sessionToken: string | undefined,
): Promise<{
id: number;
username: string;
bio: string;
Expand All @@ -15,6 +18,7 @@ export async function useUserdata(auth: string): Promise<{
}> {
const data = await fetch("https://kick.com/api/v1/user", {
headers: {
Authorization: "Bearer " + sessionToken,
"X-XSRF-TOKEN": auth,
},
method: "GET",
Expand Down
8 changes: 4 additions & 4 deletions src/site/kick.com/modules/auth/AuthButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ function closePopup(): void {
}

watchEffect(() => {
const navBlock = document.querySelector(".main-navbar");
const navBlock = document.getElementsByTagName("nav")[0];
if (navBlock) {
navBlock.lastElementChild?.insertAdjacentElement("beforebegin", navContainer);
navBlock.lastElementChild?.insertAdjacentElement("afterbegin", navContainer);
}

if (props.slug) {
const channelInfoBlock = document.querySelector(".channel-info, .stream-info");
const channelInfoBlock = document.getElementById("channel-content");
if (channelInfoBlock) {
channelInfoBlock.insertAdjacentElement("afterend", channelContainer);
channelInfoBlock.firstElementChild?.insertAdjacentElement("afterend", channelContainer);
}
}
});
Expand Down
72 changes: 72 additions & 0 deletions src/site/kick.com/modules/auth/AuthModule.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<template>
<AuthButton :slug="currentSlugDbc" />
</template>

<script setup lang="ts">
import { ref, watch } from "vue";
import { debouncedRef, useLocalStorage } from "@vueuse/core";
import { useStore } from "@/store/main";
import { LOCAL_STORAGE_KEYS } from "@/common/Constant";
import { useCookies } from "@/composable/useCookies";
import { declareModule } from "@/composable/useModule";
import { setBioCode } from "./Auth";
import AuthButton from "./AuthButton.vue";

const { markAsReady } = declareModule<"KICK">("auth", {
name: "Auth",
depends_on: [],
});

const cookies = useCookies();
const store = useStore();

const currentSlug = ref("");
const currentSlugDbc = debouncedRef(currentSlug, 1e3);

function updateSlug() {
const path = location.pathname.split("/");
if (path[1] == "popout") {
currentSlug.value = path[2];
} else {
currentSlug.value = path[1];
}
}

const observer = new MutationObserver((mutationList) => {
for (const mutation of mutationList) {
for (let i = 0; i < mutation.addedNodes.length; i++) {
if (mutation.addedNodes.item(i)?.nodeName == "TITLE") {
updateSlug();
break;
}
}
}
});

const head = document.getElementsByTagName("head")[0];
observer.observe(head, { childList: true, subtree: true });

const appToken = useLocalStorage(LOCAL_STORAGE_KEYS.APP_TOKEN, "");
const urlParams = new URLSearchParams(window.location.search);

if (urlParams.get("seventv_token")) {
watch(
() => store.identity,
(identity) => {
if (!urlParams.get("seventv_token")) return;

appToken.value = urlParams.get("seventv_token");

setBioCode(identity as KickIdentity, "", cookies).then(() => {
setTimeout(() => {
window.close();
}, 250);
});
},
{ immediate: true },
);
}

updateSlug();
markAsReady();
</script>
Loading