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

Commit 1e47f58

Browse files
committed
fix: extension auth
1 parent eeb10b1 commit 1e47f58

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

src/router/auth.route.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { RouteRecordRaw } from "vue-router";
2+
3+
export const ExtensionAuthRoute = {
4+
path: "/extension/auth",
5+
name: "ExtensionAuth",
6+
component: () => import("@/views/ExtensionAuth.vue"),
7+
} as RouteRecordRaw;

src/router/router.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { RouteRecordRaw, createRouter, createWebHistory } from "vue-router";
22
import { AdminRoute } from "./admin.route";
3+
import { ExtensionAuthRoute } from "./auth.route";
34
import { CallbackRoute } from "./callback.route";
45
import { EmoteSetRoute } from "./emote-sets.route";
56
import { EmotesRoute } from "./emotes.route";
@@ -19,6 +20,7 @@ const routes: Array<RouteRecordRaw> = [
1920
HelpRoute,
2021
AdminRoute,
2122
...CallbackRoute,
23+
ExtensionAuthRoute,
2224
{
2325
path: "/:pathMatch(.*)*",
2426
name: "Not Found",

src/views/ExtensionAuth.vue

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<template>
2+
<div class="extension-auth-content">
3+
<LoginButton v-if="!actor.user" />
4+
</div>
5+
</template>
6+
7+
<script setup lang="ts">
8+
import { watch } from "vue";
9+
import { useActor } from "@/store/actor";
10+
import { useStore } from "@/store/main";
11+
import LoginButton from "@/components/utility/LoginButton.vue";
12+
13+
const store = useStore();
14+
const actor = useActor();
15+
window.addEventListener("message", function listener(e) {
16+
if (e.origin !== "https://www.twitch.tv") return;
17+
if (e.data !== "7tv-token-request") return;
18+
19+
window.removeEventListener("message", listener);
20+
watch(
21+
() => store.authToken,
22+
(t) => {
23+
if (!t) return;
24+
e.source?.postMessage({ type: "7tv-token", token: t }, { targetOrigin: "https://www.twitch.tv/*" });
25+
},
26+
{ immediate: true },
27+
);
28+
});
29+
</script>
30+
31+
<style lang="scss">
32+
nav {
33+
display: none;
34+
}
35+
.extension-auth-content {
36+
display: flex;
37+
margin: auto;
38+
justify-content: center;
39+
}
40+
</style>

0 commit comments

Comments
 (0)