-
Notifications
You must be signed in to change notification settings - Fork 2
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 #48 from bde-isima/staging
October release
- Loading branch information
Showing
13 changed files
with
259 additions
and
58 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
Validating CODEOWNERS rules …
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,5 @@ | ||
# Learn how to add code owners here: | ||
# https://help.github.com/en/articles/about-code-owners | ||
|
||
|
||
* @bde-isima/bde |
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,11 @@ | ||
import db from 'db'; | ||
|
||
import { resolver } from '@blitzjs/rpc'; | ||
|
||
type ValidateTokenInput = { | ||
token: string; | ||
}; | ||
|
||
export default resolver.pipe(async ({ token }: ValidateTokenInput) => { | ||
await db.loginRequest.delete({ where: { token: token } }); | ||
}); |
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,34 @@ | ||
import { Ctx } from 'blitz'; | ||
import db from 'db'; | ||
|
||
import { resolver } from '@blitzjs/rpc'; | ||
|
||
type ValidateTokenInput = { | ||
token: string; | ||
}; | ||
|
||
export default resolver.pipe(async ({ token }: ValidateTokenInput, { session }: Ctx) => { | ||
const request = await db.loginRequest.findUnique({ | ||
where: { token: token }, | ||
include: { user: true } | ||
}); | ||
|
||
if (!request) return 'UnknownTokenError'; | ||
|
||
await db.loginRequest.delete({ where: { id: request.id } }); | ||
|
||
if (new Date() > request.expires) return 'ExpiredTokenError'; | ||
|
||
await session.$create({ | ||
userId: request.user.id, | ||
firstname: request.user.firstname, | ||
lastname: request.user.lastname, | ||
nickname: request.user.nickname, | ||
image: request.user.image, | ||
email: request.user.email, | ||
card: request.user.card, | ||
roles: request.user.roles | ||
}); | ||
|
||
return 'LoggedIn'; | ||
}); |
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,23 @@ | ||
import db from 'db'; | ||
|
||
import { resolver } from '@blitzjs/rpc'; | ||
|
||
type UserInfoFromTokenInput = { | ||
token: string; | ||
}; | ||
|
||
export default resolver.pipe(async ({ token }: UserInfoFromTokenInput) => { | ||
return await db.loginRequest.findUnique({ | ||
where: { token: token }, | ||
include: { | ||
user: { | ||
select: { | ||
firstname: true, | ||
lastname: true, | ||
nickname: true, | ||
image: true | ||
} | ||
} | ||
} | ||
}); | ||
}); |
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,137 @@ | ||
import { useState } from 'react'; | ||
|
||
import Button from '@mui/material/Button'; | ||
import Card from '@mui/material/Card'; | ||
import Typography from '@mui/material/Typography'; | ||
|
||
import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRightTwoTone'; | ||
|
||
import Head from 'next/head'; | ||
import Image from 'next/image'; | ||
import { NextRouter, useRouter } from 'next/router'; | ||
|
||
import { useMutation, useQuery } from '@blitzjs/rpc'; | ||
|
||
import invalidateToken from 'app/entities/auth/mutations/invalidateToken'; | ||
import validateToken from 'app/entities/auth/mutations/validateToken'; | ||
import userInfoFromToken from 'app/entities/auth/queries/userInfoFromToken'; | ||
|
||
import DefaultUser from 'public/static/images/illustrations/DefaultUser.svg'; | ||
|
||
function getToken(router: NextRouter) { | ||
try { | ||
const token = router.query.token; | ||
|
||
if (token == undefined) return ''; | ||
|
||
if (typeof token === 'string') return token; | ||
|
||
if (token.length > 0) return token[0]; | ||
} catch {} | ||
|
||
return ''; | ||
} | ||
|
||
function AuthenticatePage() { | ||
const router = useRouter(); | ||
const token = getToken(router); | ||
|
||
const [response] = useQuery(userInfoFromToken, { | ||
token: token | ||
}); | ||
const [validate] = useMutation(validateToken); | ||
const [invalidate] = useMutation(invalidateToken); | ||
|
||
const [loggedIn, setLoggedIn] = useState<boolean>(false); | ||
|
||
if (!loggedIn) { | ||
if (response == undefined) { | ||
router.push('/login?invalid=1').finally(() => {}); | ||
} else { | ||
const redirectURL = response.callbackUrl; | ||
|
||
function onAuth() { | ||
validate({ token: token }).then( | ||
(response) => { | ||
setLoggedIn(true); | ||
|
||
let redirectPath = redirectURL; | ||
if (response == 'UnknownTokenError') redirectPath = '/login?invalid=1'; | ||
if (response == 'ExpiredTokenError') redirectPath = '/login?invalid=2'; | ||
|
||
router.push(redirectPath).finally(() => {}); | ||
}, | ||
() => { | ||
router.push('/login?invalid=0').finally(() => {}); | ||
} | ||
); | ||
} | ||
|
||
function onCancel() { | ||
invalidate({ token: token }).finally(() => { | ||
router.push('/').finally(() => {}); | ||
}); | ||
} | ||
|
||
const user = response.user; | ||
|
||
let shownName = user.nickname == null ? user.firstname : response.user.nickname!; | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>Bienvenue `{shownName}`</title> | ||
</Head> | ||
|
||
<div className="flex flex-col items-center p-8"> | ||
<Card className="rounded-full z-10 p-0 flex justify-center items-center"> | ||
<Image | ||
src={user.image ? user.image : DefaultUser} | ||
width={150} | ||
height={150} | ||
alt={`Photo de ${shownName}`} | ||
quality={100} | ||
/> | ||
</Card> | ||
|
||
<Card className="py-6 px-4 rounded-md -mt-16 pt-20 max-w-sm" variant="outlined"> | ||
<div className="text-center"> | ||
<Typography variant="h4" paragraph> | ||
Bienvenue <b>{shownName}</b> | ||
</Typography> | ||
|
||
<Typography className="mb-6" variant="h6"> | ||
Bon retour parmi nous ! | ||
</Typography> | ||
|
||
<Button | ||
variant="contained" | ||
size="large" | ||
aria-label="Continuer vers le hub" | ||
color="primary" | ||
endIcon={<KeyboardArrowRightIcon />} | ||
onClick={onAuth} | ||
> | ||
Continuer vers le hub | ||
</Button> | ||
|
||
<Button | ||
variant="text" | ||
size="small" | ||
aria-label="Annuler ma connexion" | ||
color="neutral" | ||
onClick={onCancel} | ||
> | ||
Annuler ma connexion | ||
</Button> | ||
</div> | ||
</Card> | ||
</div> | ||
</> | ||
); | ||
} | ||
} | ||
} | ||
|
||
AuthenticatePage.suppressFirstRenderFlicker = true; | ||
export default AuthenticatePage; |
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,8 +1,11 @@ | ||
import { BlitzPage } from '@blitzjs/auth'; | ||
|
||
import LoginFallback from 'app/components/auth/LoginFallback'; | ||
|
||
function Login() { | ||
const Login: BlitzPage = () => { | ||
return <LoginFallback />; | ||
} | ||
}; | ||
|
||
Login.suppressFirstRenderFlicker = true; | ||
Login.redirectAuthenticatedTo = '/hub'; | ||
export default Login; |
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.