-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working on global auth, Student, Teacher, Client considered usable pr…
…ofiles
- Loading branch information
Showing
9 changed files
with
179 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
**/.git | ||
**/.svn | ||
**/.hg | ||
**/node_modules | ||
|
||
# Ignore the build directory | ||
build/ | ||
|
||
# Ignore the dist directory | ||
dist/ | ||
|
||
# Ignore the coverage directory | ||
coverage/ | ||
|
||
# Ignore the .idea directory | ||
.idea/ | ||
|
||
# Ignore the .vscode directory | ||
.vscode/ | ||
|
||
./src/pages/404.js | ||
./src/pages/profile.js |
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 |
---|---|---|
@@ -1,27 +1,24 @@ | ||
--- | ||
title: "Página no encontrada" | ||
import Layout from "@/layouts/Layout.astro" | ||
title: "Página no encontrada"; | ||
import Layout from "@/layouts/Layout.astro"; | ||
//Session handling//////////////////////////// prettier-ignore | ||
import {validateOAuth} from "@/services/server_side_logic"; // prettier-ignore | ||
import { getSession } from "auth-astro/server"; // prettier-ignore | ||
import type {SessionState} from "@/consts/types"; // prettier-ignore | ||
import type { Session } from "@auth/core/types"; // prettier-ignore | ||
const session: Session = (await getSession(Astro.request)) as Session; // prettier-ignore | ||
const sessionState: SessionState = validateOAuth(session) ? 1 : 0; // prettier-ignore | ||
//End handling////////////////////////// | ||
import type { | ||
SessionState, | ||
} from "@/consts/types"; | ||
import type { Session } from "@auth/core/types"; | ||
import { | ||
validateOAuth | ||
} from "@/services/server_side_logic"; | ||
import { getSession } from "auth-astro/server"; | ||
const session: Session = await getSession(Astro.request) as Session; | ||
const sessionState: SessionState = validateOAuth(session) ? 1 : 0; | ||
const title: string = sessionState === 0 ? "Registrate en Imagen" : "Completa tu registro"; | ||
const title: string =sessionState === 0 ? "Registrate en Imagen" : "Completa tu registro"; // prettier-ignore | ||
--- | ||
|
||
<Layout title={title}> | ||
{ | ||
sessionState === 1 | ||
? <p>Necesitas completar tu registro</p> | ||
: <p>Necesitas registrarte</p> | ||
} | ||
{ | ||
sessionState === 1 ? ( | ||
<p>Necesitas completar tu registro</p> | ||
) : ( | ||
<p>Necesitas registrarte</p> | ||
) | ||
} | ||
</Layout> |
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 |
---|---|---|
@@ -1,23 +1,52 @@ | ||
import type { Client } from "@/consts/types"; | ||
import type { Client, Result, Teacher, Student } from "@/consts/types"; | ||
|
||
export const fetchClientById = async (id: number): Promise<Client | undefined> => { | ||
try { | ||
const response = await fetch(`http:https://localhost:4321/api/clients/id/${id}`); | ||
const data: any = await response.json(); | ||
const client: Client = await data.result[0]; | ||
const data = await response.json(); | ||
const result: Result = data.result as Result; | ||
const client: Client = await result.data[0]; | ||
return client; | ||
} catch (error) { | ||
console.error("Error fetching client data:", error); | ||
} | ||
}; | ||
|
||
export const fetchClientByEmail = async (email: string): Promise<Client | undefined> => { | ||
export const fetchClientByEmail = async (email: string): Promise<Client | Teacher | Student | undefined> => { | ||
try { | ||
const response = await fetch(`http:https://localhost:4321/api/clients/email/${email}`); | ||
const data: any = await response.json(); | ||
const client: Client = await data.result[0]; | ||
const data = await response.json(); | ||
const result: Result = data.result as Result; | ||
if (data.count > 1) | ||
throw new Error("Query by unique key returned more than one registers."); | ||
const client: Client = await result.data[0]; | ||
return client; | ||
} catch (error) { | ||
console.error("Error fetching client data:", error); | ||
} | ||
}; | ||
|
||
export const fetchProfileByEmail = async (email: string): Promise<{profile: Client | Student | Teacher | undefined; table: string}> => { | ||
try { | ||
const response = await fetch(`http:https://localhost:4321/api/misc/profile/email/${email}`);// BD petition | ||
let data = await response.json(); | ||
const result: Result = data.result as Result; | ||
if (data.count > 1) | ||
throw new Error("Query by unique key returned more than one registers."); | ||
const id: number = result.data.rows[0][0] as number; | ||
const table: string = result.data.rows[0][1] as string; | ||
console.log("Profile fetched by email: ", id, table); | ||
switch (table) { | ||
case "Clients": | ||
return { | ||
profile: await fetchClientById(id), | ||
table: table | ||
};// BD petition | ||
default: | ||
throw new Error("Role not found."); | ||
} | ||
} catch (error) { | ||
console.error("Error fetching client data:", error); | ||
} | ||
return {profile: undefined, table: ""}; | ||
}; |
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