hack: allowing demo@email.com to login straight away for test flight submittion
This commit is contained in:
@ -294,17 +294,17 @@ func main() {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
|
||||
type CodeReturn struct {
|
||||
Access string `json:"access"`
|
||||
Refresh string `json:"refresh"`
|
||||
}
|
||||
|
||||
r.Post("/code", func(w http.ResponseWriter, r *http.Request) {
|
||||
type CodeBody struct {
|
||||
Email string `json:"email"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type CodeReturn struct {
|
||||
Access string `json:"access"`
|
||||
Refresh string `json:"refresh"`
|
||||
}
|
||||
|
||||
codeBody := CodeBody{}
|
||||
if err := json.NewDecoder(r.Body).Decode(&codeBody); err != nil {
|
||||
log.Println(err)
|
||||
@ -358,6 +358,39 @@ func main() {
|
||||
fmt.Fprint(w, string(json))
|
||||
})
|
||||
|
||||
r.Get("/demo-login", func(w http.ResponseWriter, r *http.Request) {
|
||||
uuid, err := userModel.GetUserIdFromEmail(r.Context(), "demo@email.com")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprintf(w, "Something went wrong.")
|
||||
return
|
||||
}
|
||||
|
||||
refresh := CreateRefreshToken(uuid)
|
||||
access := CreateAccessToken(uuid)
|
||||
|
||||
codeReturn := CodeReturn{
|
||||
Access: access,
|
||||
Refresh: refresh,
|
||||
}
|
||||
|
||||
fmt.Println(codeReturn)
|
||||
|
||||
json, err := json.Marshal(codeReturn)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprintf(w, "Something went wrong.")
|
||||
return
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
||||
fmt.Fprint(w, string(json))
|
||||
})
|
||||
|
||||
logWriter := DatabaseWriter{
|
||||
dbPool: db,
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import { TextField } from "@kobalte/core/text-field";
|
||||
import { Navigate } from "@solidjs/router";
|
||||
import { type Component, Show, createSignal } from "solid-js";
|
||||
import { isTokenValid } from "./ProtectedRoute";
|
||||
import { postCode, postLogin } from "./network";
|
||||
import { postCode, postDemoLogin, postLogin } from "./network";
|
||||
|
||||
export const Login: Component = () => {
|
||||
let form: HTMLFormElement | undefined;
|
||||
@ -18,6 +18,16 @@ export const Login: Component = () => {
|
||||
throw new Error("bruh, no email");
|
||||
}
|
||||
|
||||
if (email.toString() === "demo@email.com") {
|
||||
const { access, refresh } = await postDemoLogin();
|
||||
|
||||
localStorage.setItem("access", access);
|
||||
localStorage.setItem("refresh", refresh);
|
||||
|
||||
window.location.href = "/";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!submitted()) {
|
||||
await postLogin(email.toString());
|
||||
setSubmitted(true);
|
||||
|
@ -20,7 +20,7 @@ type BaseRequestParams = Partial<{
|
||||
method: "GET" | "POST";
|
||||
}>;
|
||||
|
||||
export const base = "http://localhost:3040";
|
||||
export const base = "https://haystack.johncosta.tech";
|
||||
|
||||
const getBaseRequest = ({ path, body, method }: BaseRequestParams): Request => {
|
||||
return new Request(`${base}/${path}`, {
|
||||
@ -202,6 +202,18 @@ export const postLogin = async (email: string): Promise<void> => {
|
||||
await fetch(request);
|
||||
};
|
||||
|
||||
export const postDemoLogin = async (): Promise<
|
||||
InferOutput<typeof codeValidator>
|
||||
> => {
|
||||
const request = getBaseRequest({
|
||||
path: "demo-login",
|
||||
});
|
||||
|
||||
const res = await fetch(request).then((res) => res.json());
|
||||
|
||||
return parse(codeValidator, res);
|
||||
};
|
||||
|
||||
const codeValidator = strictObject({
|
||||
access: string(),
|
||||
refresh: string(),
|
||||
|
Reference in New Issue
Block a user