-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/AmazeeLabs/silverback-template…
… into feat/SLB-288
- Loading branch information
Showing
50 changed files
with
1,957 additions
and
154 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
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
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,10 @@ | ||
import NextAuth from 'next-auth'; | ||
|
||
import { authConfig } from '../../nextauth.config'; | ||
|
||
// @ts-ignore | ||
export default async function handler(req, res) { | ||
const { nextauth, provider, ...rest } = req.query; | ||
req.query = { nextauth: [nextauth, provider], ...rest }; | ||
return await NextAuth(req, res, authConfig); | ||
} |
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 @@ | ||
export { default } from '../[nextauth]'; |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const AUTH_DRUPAL_URL = process.env.AUTH_DRUPAL_URL || 'http://127.0.0.1:8888'; | ||
|
||
/** @type {import("next-auth").NextAuthOptions} */ | ||
export const authConfig = { | ||
providers: [ | ||
// Drupal provider. | ||
// Other providers can be added here (e.g. Google, Keycloak). | ||
{ | ||
// Client ID and secret are set in the Drupal Consumer. | ||
clientId: process.env.AUTH_DRUPAL_ID || 'website', | ||
clientSecret: process.env.AUTH_DRUPAL_SECRET || 'banana', | ||
id: 'drupal', | ||
name: 'Drupal', | ||
type: 'oauth', | ||
// Language prefix is added to prevent 301 | ||
// that will not be handled by NextAuth. | ||
authorization: { | ||
url: `${AUTH_DRUPAL_URL}/en/oauth/authorize`, | ||
params: { | ||
scope: 'authenticated', | ||
}, | ||
}, | ||
token: `${AUTH_DRUPAL_URL}/en/oauth/token`, | ||
userinfo: { | ||
// Additional userinfo can be fetched with an extra request | ||
// using the access token. | ||
url: `${AUTH_DRUPAL_URL}/en/oauth/userinfo`, | ||
}, | ||
profile(profile, tokens) { | ||
return { | ||
id: profile.sub, | ||
name: profile.name, | ||
email: profile.email, | ||
tokens: tokens, | ||
}; | ||
}, | ||
}, | ||
], | ||
// Persist the user object in the session. | ||
// @todo use the refresh token | ||
// https://github.com/nextauthjs/next-auth-refresh-token-example/blob/main/pages/api/auth/%5B...nextauth%5D.js | ||
callbacks: { | ||
async jwt({ token, user }) { | ||
return { ...token, ...user }; | ||
}, | ||
async session({ session, token }) { | ||
session.user = token; | ||
return session; | ||
}, | ||
}, | ||
secret: process.env.NEXTAUTH_SECRET, | ||
theme: { | ||
logo: 'https://www.amazeelabs.com/images/icon.png', | ||
colorScheme: 'light', | ||
brandColor: '#951B81', | ||
}, | ||
}; |
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,38 @@ | ||
import { CurrentUserQuery, OperationExecutor } from '@custom/schema'; | ||
import { UserProfile } from '@custom/ui/routes/UserProfile'; | ||
import { useSession } from 'next-auth/react'; | ||
import React from 'react'; | ||
|
||
import { drupalExecutor } from '../utils/drupal-executor'; | ||
|
||
export default function ProfilePage() { | ||
const session = useSession(); | ||
let accessToken: string | undefined = undefined; | ||
if (session && session.status === 'authenticated') { | ||
// @ts-ignore | ||
accessToken = session.data.user.tokens.access_token; | ||
const authenticatedExecutor = drupalExecutor( | ||
`${process.env.GATSBY_DRUPAL_URL}/graphql`, | ||
false, | ||
); | ||
return ( | ||
<OperationExecutor | ||
executor={async () => { | ||
const data = await authenticatedExecutor( | ||
CurrentUserQuery, | ||
{}, | ||
accessToken, | ||
); | ||
return { | ||
currentUser: data.currentUser, | ||
}; | ||
}} | ||
id={CurrentUserQuery} | ||
> | ||
<UserProfile /> | ||
</OperationExecutor> | ||
); | ||
} else { | ||
return <UserProfile />; | ||
} | ||
} |
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,7 @@ | ||
import { GatsbyBrowser, WrapRootElementBrowserArgs } from 'gatsby'; | ||
import { SessionProvider } from 'next-auth/react'; | ||
import React from 'react'; | ||
|
||
export const WrapRootElement: GatsbyBrowser['wrapRootElement'] = ({ | ||
element, | ||
}: WrapRootElementBrowserArgs) => <SessionProvider>{element}</SessionProvider>; |
Oops, something went wrong.