Skip to content

Commit

Permalink
Merge pull request #970 from basedosdados/feat/email-gcp
Browse files Browse the repository at this point in the history
Feat/email gcp
  • Loading branch information
AldemirLucas authored Oct 7, 2024
2 parents 6a30c22 + 5b668f6 commit 33f4392
Show file tree
Hide file tree
Showing 6 changed files with 610 additions and 64 deletions.
2 changes: 1 addition & 1 deletion next/components/molecules/uiUserPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function ModalGeneral ({
minWidth={isMobileMod() ? "auto" : "536px"}
boxSizing="content-box"
padding="32px"
borderRadius="20px"
borderRadius="16px"
{...propsModalContent}
>
<ModalHeader padding="0">
Expand Down
44 changes: 44 additions & 0 deletions next/pages/api/user/changeUserGcpEmail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import axios from "axios";

const API_URL= `${process.env.NEXT_PUBLIC_API_URL}/api/v1/graphql`

async function changeUserGcpEmail(email, token) {
try {
const res = await axios({
url: API_URL,
method: "POST",
headers: {
Authorization: `Bearer ${token}`
},
data: {
query: `
mutation {
changeUserGcpEmail (email: "${email}"){
ok
errors
}
}
`
}
})
const data = res.data?.data?.changeUserGcpEmail
return data
} catch (error) {
console.error(error)
return "err"
}
}

export default async function handler(req, res) {
const token = () => {
if(req.query.q) return atob(req.query.q)
return req.cookies.token
}

const result = await changeUserGcpEmail(atob(req.query.p), token())

if(result.errors) return res.status(500).json({error: result.errors})
if(result === "err") return res.status(500).json({error: "err"})

res.status(200).json(result)
}
1 change: 1 addition & 0 deletions next/pages/api/user/getUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ async function getUser(id, token) {
isAdmin
isActive
isEmailVisible
gcpEmail
picture
username
firstName
Expand Down
44 changes: 44 additions & 0 deletions next/pages/api/user/isEmailInGoogleGroup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import axios from "axios";

const API_URL= `${process.env.NEXT_PUBLIC_API_URL}/api/v1/graphql`

async function isEmailInGoogleGroup(email, token) {
try {
const res = await axios({
url: API_URL,
method: "POST",
headers: {
Authorization: `Bearer ${token}`
},
data: {
query: `
query {
isEmailInGoogleGroup (email: "${email}"){
ok
errors
}
}
`
}
})
const data = res.data?.data?.isEmailInGoogleGroup
return data
} catch (error) {
console.error(error)
return "err"
}
}

export default async function handler(req, res) {
const token = () => {
if(req.query.q) return atob(req.query.q)
return req.cookies.token
}

const result = await isEmailInGoogleGroup(atob(req.query.p), token())

if(result.errors) return res.status(500).json({error: result.errors})
if(result === "err") return res.status(500).json({error: "err"})

res.status(200).json(result)
}
Loading

0 comments on commit 33f4392

Please sign in to comment.