-
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.
Merge pull request #900 from CodeForAfrica/vpnmanager-next-auth
@vpnmanager auth
- Loading branch information
Showing
22 changed files
with
383 additions
and
61 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 |
---|---|---|
|
@@ -8,3 +8,8 @@ SENTRY_DSN= | |
VPN_MANAGER_SENDGRID_API_KEY= | ||
[email protected] | ||
VPN_MANAGER_SENDGRID_FROM_NAME=CfA Security | ||
|
||
API_SECRET_KEY= | ||
NEXT_APP_GOOGLE_CLIENT_ID= | ||
GOOGLE_CLIENT_SECRET= | ||
ALLOWED_EMAILS= |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export async function fetchJson(path, method = "POST", body = null) { | ||
const NEXT_PUBLIC_APP_URL = process.env.NEXT_PUBLIC_APP_URL; | ||
const API_SECRET_KEY = process.env.API_SECRET_KEY; | ||
|
||
const headers = { | ||
"Content-Type": "application/json", | ||
"x-api-key": API_SECRET_KEY ?? "", | ||
}; | ||
|
||
const options = { | ||
method, | ||
headers, | ||
}; | ||
if (body) { | ||
options.body = JSON.stringify(body); | ||
} | ||
const res = await fetch(`${NEXT_PUBLIC_APP_URL}${path}`, options); | ||
if (!res.ok) { | ||
throw new Error(`API call failed with status ${res.status}`); | ||
} | ||
return res.json(); | ||
} |
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,14 +1,7 @@ | ||
import { fetchJson } from "./fetchJson.mjs"; | ||
|
||
async function main() { | ||
const NEXT_PUBLIC_APP_URL = process.env.NEXT_PUBLIC_APP_URL; | ||
const API_SECRET_KEY = process.env.API_SECRET_KEY; | ||
const headers = { | ||
"x-api-key": API_SECRET_KEY ?? "", | ||
}; | ||
const res = await fetch(`${NEXT_PUBLIC_APP_URL}/api/processGsheet`, { | ||
headers, | ||
}); | ||
return res.json(); | ||
return fetchJson("/api/users"); | ||
} | ||
|
||
const responseJson = await main(); | ||
console.log(responseJson); | ||
await main(); |
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,7 @@ | ||
import { fetchJson } from "./fetchJson.mjs"; | ||
|
||
async function main() { | ||
return fetchJson("/api/statistics"); | ||
} | ||
|
||
await main(); |
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
7 changes: 7 additions & 0 deletions
7
apps/vpnmanager/src/assets/icons/Type=google, Size=24, Color=currentColor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from "react"; | ||
import { useState } from "react"; | ||
import { Avatar, Menu, MenuItem, IconButton, Typography } from "@mui/material"; | ||
import { signOut, useSession } from "next-auth/react"; | ||
|
||
export default function UserAvatar() { | ||
const [anchorEl, setAnchorEl] = useState(null); | ||
const { data: session } = useSession(); | ||
const open = Boolean(anchorEl); | ||
|
||
const handleMenuClick = (event: React.MouseEvent<any>) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
|
||
const handleMenuClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
const handleLogout = () => { | ||
handleMenuClose(); | ||
signOut(); | ||
}; | ||
|
||
if (!session) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<IconButton onClick={handleMenuClick} size="small" sx={{ p: 2 }}> | ||
<Avatar | ||
alt={session?.user?.name || "Name"} | ||
src={session.user?.image ?? undefined} | ||
/> | ||
</IconButton> | ||
|
||
<Menu | ||
anchorEl={anchorEl} | ||
open={open} | ||
onClose={handleMenuClose} | ||
onClick={handleMenuClose} | ||
transformOrigin={{ horizontal: "right", vertical: "top" }} | ||
anchorOrigin={{ horizontal: "right", vertical: "bottom" }} | ||
> | ||
<MenuItem onClick={handleLogout}> | ||
<Typography variant="inherit">Logout</Typography> | ||
</MenuItem> | ||
</Menu> | ||
</> | ||
); | ||
} |
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,3 @@ | ||
import UserAvatar from "./UserAvatar"; | ||
|
||
export default UserAvatar; |
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 |
---|---|---|
|
@@ -50,4 +50,5 @@ export async function processNewUsers() { | |
if (fulfilled.length) { | ||
updateSheet(fulfilled); | ||
} | ||
return fulfilled; | ||
} |
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
Oops, something went wrong.