Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
fix: extension auth
Browse files Browse the repository at this point in the history
  • Loading branch information
lennartkloock committed Oct 25, 2024
1 parent eeb10b1 commit 1e47f58
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/router/auth.route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { RouteRecordRaw } from "vue-router";

export const ExtensionAuthRoute = {
path: "/extension/auth",
name: "ExtensionAuth",
component: () => import("@/views/ExtensionAuth.vue"),
} as RouteRecordRaw;
2 changes: 2 additions & 0 deletions src/router/router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RouteRecordRaw, createRouter, createWebHistory } from "vue-router";
import { AdminRoute } from "./admin.route";
import { ExtensionAuthRoute } from "./auth.route";
import { CallbackRoute } from "./callback.route";
import { EmoteSetRoute } from "./emote-sets.route";
import { EmotesRoute } from "./emotes.route";
Expand All @@ -19,6 +20,7 @@ const routes: Array<RouteRecordRaw> = [
HelpRoute,
AdminRoute,
...CallbackRoute,
ExtensionAuthRoute,
{
path: "/:pathMatch(.*)*",
name: "Not Found",
Expand Down
40 changes: 40 additions & 0 deletions src/views/ExtensionAuth.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<template>
<div class="extension-auth-content">
<LoginButton v-if="!actor.user" />
</div>
</template>

<script setup lang="ts">
import { watch } from "vue";
import { useActor } from "@/store/actor";
import { useStore } from "@/store/main";
import LoginButton from "@/components/utility/LoginButton.vue";
const store = useStore();
const actor = useActor();
window.addEventListener("message", function listener(e) {
if (e.origin !== "https://www.twitch.tv") return;
if (e.data !== "7tv-token-request") return;
window.removeEventListener("message", listener);
watch(
() => store.authToken,
(t) => {
if (!t) return;
e.source?.postMessage({ type: "7tv-token", token: t }, { targetOrigin: "https://www.twitch.tv/*" });
},
{ immediate: true },
);
});
</script>

<style lang="scss">
nav {
display: none;
}
.extension-auth-content {
display: flex;
margin: auto;
justify-content: center;
}
</style>

0 comments on commit 1e47f58

Please sign in to comment.