Fix signin and little changes
This commit is contained in:
parent
3adddef8cc
commit
16a3279e5a
11 changed files with 38 additions and 35 deletions
|
@ -4,7 +4,7 @@ import { createEffect, createMemo, createSignal } from "solid-js"
|
||||||
import { useNavigate } from "solid-start"
|
import { useNavigate } from "solid-start"
|
||||||
import { socket } from "~/lib/socket"
|
import { socket } from "~/lib/socket"
|
||||||
import { GamePropsSchema } from "~/lib/zodSchemas"
|
import { GamePropsSchema } from "~/lib/zodSchemas"
|
||||||
// import { isAuthenticated } from "~/routes/start"
|
import { isAuthenticated } from "~/routes/start"
|
||||||
import { GameSettings, PlayerEvent } from "../interfaces/frontend"
|
import { GameSettings, PlayerEvent } from "../interfaces/frontend"
|
||||||
import { useGameProps } from "./useGameProps"
|
import { useGameProps } from "./useGameProps"
|
||||||
import useIndex from "./useIndex"
|
import useIndex from "./useIndex"
|
||||||
|
@ -155,7 +155,7 @@ function useSocket() {
|
||||||
fetch("/api/game/running", {
|
fetch("/api/game/running", {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
})
|
})
|
||||||
// .then(isAuthenticated)
|
.then(isAuthenticated)
|
||||||
.then((game) => GamePropsSchema.parse(game))
|
.then((game) => GamePropsSchema.parse(game))
|
||||||
.then((res) => full(res))
|
.then((res) => full(res))
|
||||||
.catch((e) => console.log(e))
|
.catch((e) => console.log(e))
|
||||||
|
|
|
@ -6,12 +6,12 @@ const pinBodySchema = z.object({
|
||||||
pin: z.string(),
|
pin: z.string(),
|
||||||
})
|
})
|
||||||
|
|
||||||
async function getPinFromBody<T>(request: APIEvent["request"]) {
|
async function getPinFromBody(request: APIEvent["request"]) {
|
||||||
try {
|
try {
|
||||||
const body = request.json()
|
const body = request.json()
|
||||||
const { pin } = pinBodySchema.parse(body)
|
const { pin } = pinBodySchema.parse(body)
|
||||||
return pin
|
return pin
|
||||||
} catch (err: any) {
|
} catch {
|
||||||
sendError(request, {
|
sendError(request, {
|
||||||
message: "No pin in request body!",
|
message: "No pin in request body!",
|
||||||
statusCode: 401,
|
statusCode: 401,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import colors, { Color } from "colors"
|
import colors, { Color } from "colors"
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import { IncomingMessage } from "http"
|
import { IncomingMessage } from "http"
|
||||||
import { APIEvent } from "solid-start/api"
|
import { APIEvent } from "solid-start"
|
||||||
|
|
||||||
colors.enable()
|
colors.enable()
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ interface Data {
|
||||||
game: Game
|
game: Game
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function GET(request: APIEvent["request"]) {
|
export async function GET({ request }: APIEvent) {
|
||||||
const body = request.json() as any //TODO
|
const body = request.json() as any //TODO
|
||||||
const gameId = body.query.id
|
const gameId = body.query.id
|
||||||
const session = await getSession(request, authOptions)
|
const session = await getSession(request, authOptions)
|
||||||
|
|
|
@ -6,7 +6,7 @@ import prisma from "~/lib/prisma"
|
||||||
import { authOptions } from "~/server/auth"
|
import { authOptions } from "~/server/auth"
|
||||||
import { composeBody, gameSelects, getAnyRunningGame } from "./running"
|
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)
|
const session = await getSession(request, authOptions)
|
||||||
|
|
||||||
if (!session?.user) {
|
if (!session?.user) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import prisma from "~/lib/prisma"
|
||||||
import { authOptions } from "~/server/auth"
|
import { authOptions } from "~/server/auth"
|
||||||
import { composeBody, gameSelects } from "./running"
|
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 session = await getSession(request, authOptions)
|
||||||
const pin = await getPinFromBody(request)
|
const pin = await getPinFromBody(request)
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ export function composeBody(
|
||||||
return getPayloadwithChecksum(payload)
|
return getPayloadwithChecksum(payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function POST({ request }: APIEvent) {
|
export async function GET({ request }: APIEvent) {
|
||||||
const session = await getSession(request, authOptions)
|
const session = await getSession(request, authOptions)
|
||||||
|
|
||||||
if (!session?.user) {
|
if (!session?.user) {
|
||||||
|
|
|
@ -16,7 +16,7 @@ import {
|
||||||
|
|
||||||
colors.enable()
|
colors.enable()
|
||||||
|
|
||||||
export async function GET(request: RequestWithSocket) {
|
export async function GET({ request }: { request: RequestWithSocket }) {
|
||||||
if (request.socket.server.io) {
|
if (request.socket.server.io) {
|
||||||
logging("Socket is already running " + request.url, ["infoCyan"], request)
|
logging("Socket is already running " + request.url, ["infoCyan"], request)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -39,7 +39,7 @@ const errors: Record<SignInErrorTypes, string> = {
|
||||||
|
|
||||||
function Login() {
|
function Login() {
|
||||||
const [email, setEmail] = createSignal("")
|
const [email, setEmail] = createSignal("")
|
||||||
const { state } = useSession()
|
const { latest } = useSession()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const [searchParams] = useSearchParams()
|
const [searchParams] = useSearchParams()
|
||||||
|
|
||||||
|
@ -51,12 +51,11 @@ function Login() {
|
||||||
})
|
})
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
if (state === "ready") navigate("/") //TODO
|
if (latest?.user?.id) navigate("/")
|
||||||
})
|
})
|
||||||
|
|
||||||
function login(provider: "email" | "azure-ad") {
|
const login = (provider: "email" | "azure-ad") =>
|
||||||
return () => signIn(provider, { email, callbackUrl: "/" })
|
signIn(provider, { email: email(), callbackUrl: "/" })
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
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">
|
<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
|
<button
|
||||||
id="email-submit"
|
id="email-submit"
|
||||||
type="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"
|
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
|
Sign in with Email
|
||||||
|
@ -124,7 +123,7 @@ function Login() {
|
||||||
</a>
|
</a>
|
||||||
<button
|
<button
|
||||||
id="microsoft"
|
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"
|
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
|
<img
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { faPlus, faUserPlus } from "@fortawesome/pro-solid-svg-icons"
|
||||||
import { GamePropsSchema } from "~/lib/zodSchemas"
|
import { GamePropsSchema } from "~/lib/zodSchemas"
|
||||||
// import OtpInput from "react-otp-input"
|
// import OtpInput from "react-otp-input"
|
||||||
// import { Icons, toast } from "react-toastify"
|
// import { Icons, toast } from "react-toastify"
|
||||||
|
import status from "http-status"
|
||||||
import { createEffect, createMemo, createSignal } from "solid-js"
|
import { createEffect, createMemo, createSignal } from "solid-js"
|
||||||
import { useLocation, useNavigate, useSearchParams } from "solid-start"
|
import { useLocation, useNavigate, useSearchParams } from "solid-start"
|
||||||
import BurgerMenu from "~/components/BurgerMenu"
|
import BurgerMenu from "~/components/BurgerMenu"
|
||||||
|
@ -12,22 +13,22 @@ import OptionButton from "~/components/OptionButton"
|
||||||
import { useGameProps } from "~/hooks/useGameProps"
|
import { useGameProps } from "~/hooks/useGameProps"
|
||||||
import { useSession } from "~/hooks/useSession"
|
import { useSession } from "~/hooks/useSession"
|
||||||
|
|
||||||
// export function isAuthenticated(res: Response) {
|
export function isAuthenticated(res: Response) {
|
||||||
// switch (status[`${res.status}_CLASS`]) {
|
switch (status[`${res.status}_CLASS`]) {
|
||||||
// case status.classes.SUCCESSFUL:
|
case status.classes.SUCCESSFUL:
|
||||||
// case status.classes.REDIRECTION:
|
case status.classes.REDIRECTION:
|
||||||
// return res.json()
|
return res.json()
|
||||||
// }
|
}
|
||||||
|
|
||||||
// const resStatus = status[`${res.status}_CLASS`]
|
const resStatus = status[`${res.status}_CLASS`]
|
||||||
// if (typeof resStatus !== "string") return
|
if (typeof resStatus !== "string") return
|
||||||
|
|
||||||
// // toast(status[res.status], {
|
// toast(status[res.status], {
|
||||||
// // position: "top-center",
|
// position: "top-center",
|
||||||
// // type: "info",
|
// type: "info",
|
||||||
// // theme: "colored",
|
// theme: "colored",
|
||||||
// // })
|
// })
|
||||||
// }
|
}
|
||||||
|
|
||||||
const handleConfirmation = () => {
|
const handleConfirmation = () => {
|
||||||
const toastId = "confirm"
|
const toastId = "confirm"
|
||||||
|
@ -69,7 +70,7 @@ export default function Start() {
|
||||||
body: JSON.stringify({ pin }),
|
body: JSON.stringify({ pin }),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
// .then(isAuthenticated)
|
.then(isAuthenticated)
|
||||||
.then((game) => GamePropsSchema.parse(game))
|
.then((game) => GamePropsSchema.parse(game))
|
||||||
|
|
||||||
const move = !pin ? "erstellt" : "angefragt"
|
const move = !pin ? "erstellt" : "angefragt"
|
||||||
|
|
9
leaky-ships/src/types/authjs.d.ts
vendored
9
leaky-ships/src/types/authjs.d.ts
vendored
|
@ -1,12 +1,15 @@
|
||||||
import { DefaultSession } from "@auth/core/types"
|
import { DefaultSession as DSession } from "@auth/core/types"
|
||||||
|
|
||||||
declare module "@auth/core/types" {
|
declare module "@auth/core/types" {
|
||||||
/**
|
/**
|
||||||
* Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
|
* Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
|
||||||
*/
|
*/
|
||||||
interface Session {
|
interface Session extends DSession {
|
||||||
user?: {
|
user?: {
|
||||||
id: string
|
id: string
|
||||||
} & DefaultSession["user"]
|
name?: string | null
|
||||||
|
email?: string | null
|
||||||
|
image?: string | null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue