-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
feace89
commit 3284b03
Showing
12 changed files
with
128 additions
and
13 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
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,32 @@ | ||
<script> | ||
import {page} from "$app/stores"; | ||
import {env} from '$env/dynamic/public'; | ||
import {SIGNIN_REDIRECT_URL} from "$lib/config"; | ||
let url = new URL("https://id.twitch.tv/oauth2/authorize") | ||
url.searchParams.set("client_id", env.PUBLIC_TWITCH_CLIENT_ID) | ||
url.searchParams.set("redirect_uri", SIGNIN_REDIRECT_URL) | ||
url.searchParams.set("response_type", "token") | ||
url.searchParams.set("scope", "chat:read channel:read:redemptions") | ||
let isSignedIn = !!$page.data.profile | ||
</script> | ||
|
||
{#if isSignedIn} | ||
<div>Привет, {$page.data.profile.userName}!</div> | ||
{:else} | ||
<a href={url.href}>Войти</a> | ||
{/if} | ||
|
||
<style> | ||
a { | ||
padding: 0.5em 1.2em; | ||
color: white; | ||
background-color: var(--color-twitch); | ||
text-decoration: none; | ||
} | ||
a:hover { | ||
text-decoration: none; | ||
} | ||
</style> |
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,16 @@ | ||
import type { LayoutServerLoad } from "./$types" | ||
|
||
export const load = (async ({ cookies }) => { | ||
const user = cookies.get("chat-game-twitch-access-token") | ||
if (!user) { | ||
return { | ||
profile: null | ||
} | ||
} | ||
|
||
return { | ||
profile: { | ||
userName: "123" | ||
} | ||
} | ||
}) satisfies LayoutServerLoad |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { json, error } from '@sveltejs/kit'; | ||
import type { RequestHandler } from './$types'; | ||
|
||
export const GET: RequestHandler = async ({ cookies }) => { | ||
const user = cookies.get("chat-game-twitch-access-token") | ||
if (!user) { | ||
return error(401) | ||
} | ||
|
||
return json({ | ||
profile: { | ||
userName: "123" | ||
} | ||
}) | ||
}; |
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,19 @@ | ||
<script lang="ts"> | ||
import { page } from "$app/stores"; | ||
if ($page.url.hash) { | ||
const hash = $page.url.hash.split("#")[1] | ||
void fetch('/auth/sign-in', { | ||
method: 'POST', | ||
body: JSON.stringify({ hash }), | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
}).then(res => res.ok && location.assign("/")) | ||
} | ||
</script> | ||
|
||
<div> | ||
Sign In | ||
</div> |
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,24 @@ | ||
import { json } from '@sveltejs/kit'; | ||
import type { RequestHandler } from './$types'; | ||
|
||
export const POST: RequestHandler = async ({ request, cookies }) => { | ||
const data = await request.json() | ||
if (!data?.hash) { | ||
return json({ | ||
ok: false | ||
}) | ||
} | ||
|
||
const items = new URLSearchParams(data.hash); | ||
|
||
if (items.has("access_token")) { | ||
const accessToken = items.get("access_token") | ||
if (accessToken) { | ||
cookies.set("chat-game-twitch-access-token", accessToken, { path: "/" }) | ||
} | ||
} | ||
|
||
return json({ | ||
ok: true | ||
}) | ||
}; |
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