Fix signin and little changes

This commit is contained in:
aronmal 2023-08-16 01:37:34 +02:00
parent 3adddef8cc
commit 16a3279e5a
Signed by: aronmal
GPG key ID: 816B7707426FC612
11 changed files with 38 additions and 35 deletions

View file

@ -4,7 +4,7 @@ import { createEffect, createMemo, createSignal } from "solid-js"
import { useNavigate } from "solid-start"
import { socket } from "~/lib/socket"
import { GamePropsSchema } from "~/lib/zodSchemas"
// import { isAuthenticated } from "~/routes/start"
import { isAuthenticated } from "~/routes/start"
import { GameSettings, PlayerEvent } from "../interfaces/frontend"
import { useGameProps } from "./useGameProps"
import useIndex from "./useIndex"
@ -155,7 +155,7 @@ function useSocket() {
fetch("/api/game/running", {
method: "GET",
})
// .then(isAuthenticated)
.then(isAuthenticated)
.then((game) => GamePropsSchema.parse(game))
.then((res) => full(res))
.catch((e) => console.log(e))

View file

@ -6,12 +6,12 @@ const pinBodySchema = z.object({
pin: z.string(),
})
async function getPinFromBody<T>(request: APIEvent["request"]) {
async function getPinFromBody(request: APIEvent["request"]) {
try {
const body = request.json()
const { pin } = pinBodySchema.parse(body)
return pin
} catch (err: any) {
} catch {
sendError(request, {
message: "No pin in request body!",
statusCode: 401,

View file

@ -1,7 +1,7 @@
import colors, { Color } from "colors"
import fs from "fs"
import { IncomingMessage } from "http"
import { APIEvent } from "solid-start/api"
import { APIEvent } from "solid-start"
colors.enable()

View file

@ -10,7 +10,7 @@ interface Data {
game: Game
}
export async function GET(request: APIEvent["request"]) {
export async function GET({ request }: APIEvent) {
const body = request.json() as any //TODO
const gameId = body.query.id
const session = await getSession(request, authOptions)

View file

@ -6,7 +6,7 @@ import prisma from "~/lib/prisma"
import { authOptions } from "~/server/auth"
import { composeBody, gameSelects, getAnyRunningGame } from "./running"
export async function POST(request: APIEvent["request"]) {
export async function POST({ request }: APIEvent) {
const session = await getSession(request, authOptions)
if (!session?.user) {

View file

@ -9,7 +9,7 @@ import prisma from "~/lib/prisma"
import { authOptions } from "~/server/auth"
import { composeBody, gameSelects } from "./running"
export async function POST(request: APIEvent["request"]) {
export async function POST({ request }: APIEvent) {
const session = await getSession(request, authOptions)
const pin = await getPinFromBody(request)

View file

@ -123,7 +123,7 @@ export function composeBody(
return getPayloadwithChecksum(payload)
}
export async function POST({ request }: APIEvent) {
export async function GET({ request }: APIEvent) {
const session = await getSession(request, authOptions)
if (!session?.user) {

View file

@ -16,7 +16,7 @@ import {
colors.enable()
export async function GET(request: RequestWithSocket) {
export async function GET({ request }: { request: RequestWithSocket }) {
if (request.socket.server.io) {
logging("Socket is already running " + request.url, ["infoCyan"], request)
} else {

View file

@ -39,7 +39,7 @@ const errors: Record<SignInErrorTypes, string> = {
function Login() {
const [email, setEmail] = createSignal("")
const { state } = useSession()
const { latest } = useSession()
const navigate = useNavigate()
const [searchParams] = useSearchParams()
@ -51,12 +51,11 @@ function Login() {
})
createEffect(() => {
if (state === "ready") navigate("/") //TODO
if (latest?.user?.id) navigate("/")
})
function login(provider: "email" | "azure-ad") {
return () => signIn(provider, { email, callbackUrl: "/" })
}
const login = (provider: "email" | "azure-ad") =>
signIn(provider, { email: email(), callbackUrl: "/" })
return (
<div class="flex h-screen w-full items-center justify-center bg-gray-900 bg-[url('/images/wallpaper.jpg')] bg-cover bg-center bg-no-repeat">
@ -96,7 +95,7 @@ function Login() {
<button
id="email-submit"
type="submit"
onclick={login("email")}
onClick={() => login("email")}
class="my-1 rounded-lg bg-blue-500 bg-opacity-75 px-10 py-3 text-white shadow-inner drop-shadow-md backdrop-blur-md transition-colors duration-300 hover:bg-blue-600"
>
Sign in with Email
@ -124,7 +123,7 @@ function Login() {
</a>
<button
id="microsoft"
onClick={login("azure-ad")}
onClick={() => login("azure-ad")}
class="flex w-full justify-evenly rounded-lg border border-gray-400 bg-slate-100 px-5 py-3 text-black drop-shadow-md duration-300 hover:bg-slate-200"
>
<img

View file

@ -3,6 +3,7 @@ import { faPlus, faUserPlus } from "@fortawesome/pro-solid-svg-icons"
import { GamePropsSchema } from "~/lib/zodSchemas"
// import OtpInput from "react-otp-input"
// import { Icons, toast } from "react-toastify"
import status from "http-status"
import { createEffect, createMemo, createSignal } from "solid-js"
import { useLocation, useNavigate, useSearchParams } from "solid-start"
import BurgerMenu from "~/components/BurgerMenu"
@ -12,22 +13,22 @@ import OptionButton from "~/components/OptionButton"
import { useGameProps } from "~/hooks/useGameProps"
import { useSession } from "~/hooks/useSession"
// export function isAuthenticated(res: Response) {
// switch (status[`${res.status}_CLASS`]) {
// case status.classes.SUCCESSFUL:
// case status.classes.REDIRECTION:
// return res.json()
// }
export function isAuthenticated(res: Response) {
switch (status[`${res.status}_CLASS`]) {
case status.classes.SUCCESSFUL:
case status.classes.REDIRECTION:
return res.json()
}
// const resStatus = status[`${res.status}_CLASS`]
// if (typeof resStatus !== "string") return
const resStatus = status[`${res.status}_CLASS`]
if (typeof resStatus !== "string") return
// // toast(status[res.status], {
// // position: "top-center",
// // type: "info",
// // theme: "colored",
// // })
// }
// toast(status[res.status], {
// position: "top-center",
// type: "info",
// theme: "colored",
// })
}
const handleConfirmation = () => {
const toastId = "confirm"
@ -69,7 +70,7 @@ export default function Start() {
body: JSON.stringify({ pin }),
},
)
// .then(isAuthenticated)
.then(isAuthenticated)
.then((game) => GamePropsSchema.parse(game))
const move = !pin ? "erstellt" : "angefragt"

View file

@ -1,12 +1,15 @@
import { DefaultSession } from "@auth/core/types"
import { DefaultSession as DSession } from "@auth/core/types"
declare module "@auth/core/types" {
/**
* Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
*/
interface Session {
interface Session extends DSession {
user?: {
id: string
} & DefaultSession["user"]
name?: string | null
email?: string | null
image?: string | null
}
}
}