mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
Compare commits
10 Commits
next-auth@
...
next-auth@
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0cbeb4055e | ||
|
|
5a128db369 | ||
|
|
c385cf8c7c | ||
|
|
53fa46744c | ||
|
|
451eaaabd2 | ||
|
|
f54424c216 | ||
|
|
09bcc1d504 | ||
|
|
6ecf9cb93d | ||
|
|
ba2711d279 | ||
|
|
03881bf98f |
2
.github/workflows/sync-examples.yml
vendored
2
.github/workflows/sync-examples.yml
vendored
@@ -14,5 +14,5 @@ jobs:
|
||||
# Can update to v1 when https://github.com/BetaHuhn/repo-file-sync-action/issues/168 is resolved
|
||||
uses: BetaHuhn/repo-file-sync-action@v1.16.5
|
||||
with:
|
||||
GH_PAT: ${{ secrets.SYNC_EXAMPLE_PAT }}
|
||||
GH_PAT: ${{ secrets.GH_PAT_CLASSIC }}
|
||||
SKIP_PR: true
|
||||
|
||||
@@ -65,7 +65,7 @@ export default function Component() {
|
||||
|
||||
### Require session
|
||||
|
||||
Due to the way how Next.js handles `getServerSideProps` and `getInitialProps`, every protected page load has to make a server-side request to check if the session is valid and then generate the requested page (SSR). This increases server load, and if you are good with making the requests from the client, there is an alternative. You can use `useSession` in a way that makes sure you always have a valid session. If after the initial loading state there was no session found, you can define the appropriate action to respond.
|
||||
Due to the way Next.js handles `getServerSideProps` and `getInitialProps`, every protected page load has to make a server-side request to check if the session is valid and then generate the requested page (SSR). This increases server load, and if you are good with making the requests from the client, there is an alternative. You can use `useSession` in a way that makes sure you always have a valid session. If after the initial loading state there was no session found, you can define the appropriate action to respond.
|
||||
|
||||
The default behavior is to redirect the user to the sign-in page, from where - after a successful login - they will be sent back to the page they started on. You can also define an `onUnauthenticated()` callback, if you would like to do something else:
|
||||
|
||||
|
||||
@@ -35,27 +35,3 @@ providers: [
|
||||
]
|
||||
...
|
||||
```
|
||||
|
||||
## Demo IdentityServer
|
||||
|
||||
The configuration below is for the demo server at https://demo.identityserver.io/
|
||||
|
||||
If you want to try it out, you can copy and paste the configuration below.
|
||||
|
||||
You can sign in to the demo service with either <b>bob/bob</b> or <b>alice/alice</b>.
|
||||
|
||||
```js
|
||||
import IdentityServer4Provider from `next-auth/providers/identity-server4`
|
||||
...
|
||||
providers: [
|
||||
IdentityServer4Provider({
|
||||
id: "demo-identity-server",
|
||||
name: "Demo IdentityServer4",
|
||||
authorization: { params: { scope: "openid profile email api offline_access" } },
|
||||
issuer: "https://demo.identityserver.io/",
|
||||
clientId: "interactive.confidential",
|
||||
clientSecret: "secret",
|
||||
})
|
||||
}
|
||||
...
|
||||
```
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "next-auth",
|
||||
"version": "4.18.8",
|
||||
"version": "4.18.10",
|
||||
"description": "Authentication for Next.js",
|
||||
"homepage": "https://next-auth.js.org",
|
||||
"repository": "https://github.com/nextauthjs/next-auth.git",
|
||||
@@ -127,8 +127,5 @@
|
||||
"react": "^18",
|
||||
"react-dom": "^18",
|
||||
"whatwg-fetch": "^3.6.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.19.0 || ^14.15.0 || ^16.13.0 || ^18.12.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ export default function SigninPage(props: SignInServerPageParams) {
|
||||
|
||||
const error = errorType && (errors[errorType] ?? errors.default)
|
||||
|
||||
const logos = "https://authjs.dev/img/providers"
|
||||
return (
|
||||
<div className="signin">
|
||||
{theme.brandColor && (
|
||||
@@ -117,14 +118,24 @@ export default function SigninPage(props: SignInServerPageParams) {
|
||||
>
|
||||
{provider.style?.logo && (
|
||||
<img
|
||||
loading="lazy"
|
||||
height={24}
|
||||
width={24}
|
||||
id="provider-logo"
|
||||
src={`https://authjs.dev/img/providers/${provider.style.logo}`}
|
||||
src={`${
|
||||
provider.style.logo.startsWith("/") ? logos : ""
|
||||
}${provider.style.logo}`}
|
||||
/>
|
||||
)}
|
||||
{provider.style?.logoDark && (
|
||||
<img
|
||||
loading="lazy"
|
||||
height={24}
|
||||
width={24}
|
||||
id="provider-logo-dark"
|
||||
src={`https://authjs.dev/img/providers/${provider.style.logoDark}`}
|
||||
src={`${
|
||||
provider.style.logo.startsWith("/") ? logos : ""
|
||||
}${provider.style.logoDark}`}
|
||||
/>
|
||||
)}
|
||||
<span>Sign in with {provider.name}</span>
|
||||
|
||||
@@ -118,8 +118,8 @@ export default function Apple<P extends AppleProfile>(
|
||||
},
|
||||
checks: ["pkce"],
|
||||
style: {
|
||||
logo: "apple.svg",
|
||||
logoDark: "apple-dark.svg",
|
||||
logo: "/apple.svg",
|
||||
logoDark: "/apple-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#000",
|
||||
bgDark: "#000",
|
||||
|
||||
@@ -32,8 +32,8 @@ export default function Atlassian<P extends AtlassianProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "atlassian.svg",
|
||||
logoDark: "atlassian-dark.svg",
|
||||
logo: "/atlassian.svg",
|
||||
logoDark: "/atlassian-dark.svg",
|
||||
bg: "#0052cc",
|
||||
text: "#fff",
|
||||
bgDark: "#fff",
|
||||
|
||||
@@ -27,8 +27,8 @@ export default function Auth0<P extends Auth0Profile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "auth0.svg",
|
||||
logoDark: "auth0-dark.svg",
|
||||
logo: "/auth0.svg",
|
||||
logoDark: "/auth0-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#EB5424",
|
||||
bgDark: "#EB5424",
|
||||
|
||||
@@ -43,8 +43,8 @@ export default function AzureADB2C<P extends AzureB2CProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "azure.svg",
|
||||
logoDark: "azure-dark.svg",
|
||||
logo: "/azure.svg",
|
||||
logoDark: "/azure-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#0072c6",
|
||||
bgDark: "#0072c6",
|
||||
|
||||
@@ -33,36 +33,32 @@ export default function AzureAD<P extends AzureADProfile>(
|
||||
},
|
||||
async profile(profile, tokens) {
|
||||
// https://docs.microsoft.com/en-us/graph/api/profilephoto-get?view=graph-rest-1.0#examples
|
||||
const profilePicture = await fetch(
|
||||
const response = await fetch(
|
||||
`https://graph.microsoft.com/v1.0/me/photos/${profilePhotoSize}x${profilePhotoSize}/$value`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${tokens.access_token}`,
|
||||
},
|
||||
}
|
||||
{ headers: { Authorization: `Bearer ${tokens.access_token}` } }
|
||||
)
|
||||
|
||||
// Confirm that profile photo was returned
|
||||
if (profilePicture.ok) {
|
||||
const pictureBuffer = await profilePicture.arrayBuffer()
|
||||
const pictureBase64 = Buffer.from(pictureBuffer).toString("base64")
|
||||
return {
|
||||
id: profile.sub,
|
||||
name: profile.name,
|
||||
email: profile.email,
|
||||
image: `data:image/jpeg;base64, ${pictureBase64}`,
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
id: profile.sub,
|
||||
name: profile.name,
|
||||
email: profile.email,
|
||||
}
|
||||
let image
|
||||
// TODO: Do this without Buffer
|
||||
if (response.ok && typeof Buffer !== "undefined") {
|
||||
try {
|
||||
const pictureBuffer = await response.arrayBuffer()
|
||||
const pictureBase64 = Buffer.from(pictureBuffer).toString("base64")
|
||||
image = `data:image/jpeg;base64, ${pictureBase64}`
|
||||
} catch {}
|
||||
}
|
||||
|
||||
return {
|
||||
id: profile.sub,
|
||||
name: profile.name,
|
||||
email: profile.email,
|
||||
image: image ?? null,
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "azure.svg",
|
||||
logoDark: "azure-dark.svg",
|
||||
logo: "/azure.svg",
|
||||
logoDark: "/azure-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#0072c6",
|
||||
bgDark: "#0072c6",
|
||||
|
||||
@@ -27,8 +27,8 @@ export default function BattleNet<P extends BattleNetProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "battlenet.svg",
|
||||
logoDark: "battlenet-dark.svg",
|
||||
logo: "/battlenet.svg",
|
||||
logoDark: "/battlenet-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#148eff",
|
||||
bgDark: "#148eff",
|
||||
|
||||
@@ -16,8 +16,8 @@ export default function Box(options) {
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "box.svg",
|
||||
logoDark: "box-dark.svg",
|
||||
logo: "/box.svg",
|
||||
logoDark: "/box-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#0075C9",
|
||||
bgDark: "#0075C9",
|
||||
|
||||
@@ -25,8 +25,8 @@ export default function Cognito<P extends CognitoProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "cognito.svg",
|
||||
logoDark: "cognito.svg",
|
||||
logo: "/cognito.svg",
|
||||
logoDark: "/cognito.svg",
|
||||
bg: "#fff",
|
||||
text: "#C17B9E",
|
||||
bgDark: "#fff",
|
||||
|
||||
@@ -45,8 +45,8 @@ export default function Discord<P extends DiscordProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "discord.svg",
|
||||
logoDark: "discord-dark.svg",
|
||||
logo: "/discord.svg",
|
||||
logoDark: "/discord-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#7289DA",
|
||||
bgDark: "#7289DA",
|
||||
|
||||
@@ -42,8 +42,8 @@ export default function Facebook<P extends FacebookProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "facebook.svg",
|
||||
logoDark: "facebook-dark.svg",
|
||||
logo: "/facebook.svg",
|
||||
logoDark: "/facebook-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#006aff",
|
||||
bgDark: "#006aff",
|
||||
|
||||
@@ -51,8 +51,8 @@ export default function Foursquare(options) {
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "foursquare.svg",
|
||||
logoDark: "foursquare-dark.svg",
|
||||
logo: "/foursquare.svg",
|
||||
logoDark: "/foursquare-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#000",
|
||||
bgDark: "#000",
|
||||
|
||||
@@ -18,8 +18,8 @@ export default function Freshbooks(options) {
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "freshbooks.svg",
|
||||
logoDark: "freshbooks-dark.svg",
|
||||
logo: "/freshbooks.svg",
|
||||
logoDark: "/freshbooks-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#0075dd",
|
||||
bgDark: "#0075dd",
|
||||
|
||||
@@ -99,8 +99,8 @@ export default function Github<P extends GithubProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "github.svg",
|
||||
logoDark: "github-dark.svg",
|
||||
logo: "/github.svg",
|
||||
logoDark: "/github-dark.svg",
|
||||
bg: "#fff",
|
||||
bgDark: "#000",
|
||||
text: "#000",
|
||||
|
||||
@@ -68,8 +68,8 @@ export default function GitLab<P extends GitLabProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "gitlab.svg",
|
||||
logoDark: "gitlab-dark.svg",
|
||||
logo: "/gitlab.svg",
|
||||
logoDark: "/gitlab-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#FC6D26",
|
||||
bgDark: "#FC6D26",
|
||||
|
||||
@@ -38,8 +38,8 @@ export default function Google<P extends GoogleProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "google.svg",
|
||||
logoDark: "google.svg",
|
||||
logo: "/google.svg",
|
||||
logoDark: "/google.svg",
|
||||
bgDark: "#fff",
|
||||
bg: "#fff",
|
||||
text: "#000",
|
||||
|
||||
@@ -65,8 +65,8 @@ export default function HubSpot<P extends HubSpotProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "hubspot.svg",
|
||||
logoDark: "hubspot-dark.svg",
|
||||
logo: "/hubspot.svg",
|
||||
logoDark: "/hubspot-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#ff7a59",
|
||||
bgDark: "#ff7a59",
|
||||
|
||||
@@ -47,8 +47,8 @@ export default function Instagram(options) {
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "instagram.svg",
|
||||
logoDark: "instagram.svg",
|
||||
logo: "/instagram.svg",
|
||||
logoDark: "/instagram.svg",
|
||||
bg: "#fff",
|
||||
text: "#000",
|
||||
bgDark: "#fff",
|
||||
|
||||
@@ -44,8 +44,8 @@ export default function Keycloak<P extends KeycloakProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "keycloak.svg",
|
||||
logoDark: "keycloak.svg",
|
||||
logo: "/keycloak.svg",
|
||||
logoDark: "/keycloak.svg",
|
||||
bg: "#fff",
|
||||
text: "#000",
|
||||
bgDark: "#fff",
|
||||
|
||||
@@ -34,8 +34,8 @@ export default function LINE<P extends LineProfile>(
|
||||
id_token_signed_response_alg: "HS256",
|
||||
},
|
||||
style: {
|
||||
logo: "line.svg",
|
||||
logoDark: "line.svg",
|
||||
logo: "/line.svg",
|
||||
logoDark: "/line.svg",
|
||||
bg: "#fff",
|
||||
text: "#00C300",
|
||||
bgDark: "#00C300",
|
||||
|
||||
@@ -56,8 +56,8 @@ export default function LinkedIn<P extends LinkedInProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "linkedin.svg",
|
||||
logoDark: "linkedin-dark.svg",
|
||||
logo: "/linkedin.svg",
|
||||
logoDark: "/linkedin-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#069",
|
||||
bgDark: "#069",
|
||||
|
||||
@@ -16,8 +16,8 @@ export default function Mailchimp(options) {
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "mailchimp.svg",
|
||||
logoDark: "mailchimp-dark.svg",
|
||||
logo: "/mailchimp.svg",
|
||||
logoDark: "/mailchimp-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#000",
|
||||
bgDark: "#000",
|
||||
|
||||
@@ -53,8 +53,8 @@ export default function Okta<P extends OktaProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "okta.svg",
|
||||
logoDark: "okta-dark.svg",
|
||||
logo: "/okta.svg",
|
||||
logoDark: "/okta-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#000",
|
||||
bgDark: "#000",
|
||||
|
||||
@@ -30,8 +30,8 @@ export default function Patreon<P extends PatreonProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "patreon.svg",
|
||||
logoDark: "patreon.svg",
|
||||
logo: "/patreon.svg",
|
||||
logoDark: "/patreon.svg",
|
||||
bg: "#fff",
|
||||
text: "#e85b46",
|
||||
bgDark: "#000",
|
||||
|
||||
@@ -50,8 +50,8 @@ export default function Slack<P extends SlackProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "slack.svg",
|
||||
logoDark: "slack.svg",
|
||||
logo: "/slack.svg",
|
||||
logoDark: "/slack.svg",
|
||||
bg: "#fff",
|
||||
text: "#000",
|
||||
bgDark: "#000",
|
||||
|
||||
@@ -30,8 +30,8 @@ export default function Spotify<P extends SpotifyProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "spotify.svg",
|
||||
logoDark: "spotify.svg",
|
||||
logo: "/spotify.svg",
|
||||
logoDark: "/spotify.svg",
|
||||
bg: "#fff",
|
||||
text: "#2ebd59",
|
||||
bgDark: "#fff",
|
||||
|
||||
@@ -54,8 +54,8 @@ export default function TodoistProvider<P extends TodoistProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "todoist.svg",
|
||||
logoDark: "todoist.svg",
|
||||
logo: "/todoist.svg",
|
||||
logoDark: "/todoist.svg",
|
||||
bg: "#fff",
|
||||
text: "#E44332",
|
||||
bgDark: "#000",
|
||||
|
||||
@@ -52,8 +52,8 @@ export default function Trakt<P extends TraktUser>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "trakt.svg",
|
||||
logoDark: "trakt-dark.svg",
|
||||
logo: "/trakt.svg",
|
||||
logoDark: "/trakt-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#ED2224",
|
||||
bgDark: "#ED2224",
|
||||
|
||||
@@ -37,8 +37,8 @@ export default function Twitch<P extends TwitchProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "twitch.svg",
|
||||
logoDark: "twitch-dark.svg",
|
||||
logo: "/twitch.svg",
|
||||
logoDark: "/twitch-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#65459B",
|
||||
bgDark: "#65459B",
|
||||
|
||||
@@ -120,8 +120,8 @@ export function TwitterLegacy<
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "twitter.svg",
|
||||
logoDark: "twitter-dark.svg",
|
||||
logo: "/twitter.svg",
|
||||
logoDark: "/twitter-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#1da1f2",
|
||||
bgDark: "#1da1f2",
|
||||
@@ -215,8 +215,8 @@ export default function Twitter<
|
||||
},
|
||||
checks: ["pkce", "state"],
|
||||
style: {
|
||||
logo: "twitter.svg",
|
||||
logoDark: "twitter-dark.svg",
|
||||
logo: "/twitter.svg",
|
||||
logoDark: "/twitter-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#1da1f2",
|
||||
bgDark: "#1da1f2",
|
||||
|
||||
@@ -306,8 +306,8 @@ export default function VK<P extends Record<string, any> = VkProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "vk.svg",
|
||||
logoDark: "vk-dark.svg",
|
||||
logo: "/vk.svg",
|
||||
logoDark: "/vk-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#07F",
|
||||
bgDark: "#07F",
|
||||
|
||||
@@ -181,8 +181,8 @@ export default function Wikimedia<P extends WikimediaProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "wikimedia.svg",
|
||||
logoDark: "wikimedia-dark.svg",
|
||||
logo: "/wikimedia.svg",
|
||||
logoDark: "/wikimedia-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#000",
|
||||
bgDark: "#000",
|
||||
|
||||
@@ -45,8 +45,8 @@ export default function WorkOS<P extends WorkOSProfile>(
|
||||
}
|
||||
},
|
||||
style: {
|
||||
logo: "workos.svg",
|
||||
logoDark: "workos-dark.svg",
|
||||
logo: "/workos.svg",
|
||||
logoDark: "/workos-dark.svg",
|
||||
bg: "#fff",
|
||||
text: "#6363f1",
|
||||
bgDark: "#6363f1",
|
||||
|
||||
Reference in New Issue
Block a user