mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59985264a2 | ||
|
|
c844296982 | ||
|
|
d1aa2a1a8e | ||
|
|
8139126f29 | ||
|
|
aa0e8200b3 |
@@ -54,7 +54,7 @@ See [next-auth.js.org](https://next-auth.js.org) for more information and docume
|
||||
### Flexible and easy to use
|
||||
|
||||
- Designed to work with any OAuth service, it supports OAuth 1.0, 1.0A and 2.0
|
||||
- Built-in support for [many popular sign-in services](https://next-auth.js.org/configuration/providers)
|
||||
- Built-in support for [many popular sign-in services](https://next-auth.js.org/providers/overview)
|
||||
- Supports email / passwordless authentication
|
||||
- Supports stateless authentication with any backend (Active Directory, LDAP, etc)
|
||||
- Supports both JSON Web Tokens and database sessions
|
||||
|
||||
@@ -92,8 +92,11 @@ export async function NextAuthHandler<
|
||||
switch (action) {
|
||||
case "providers":
|
||||
return (await routes.providers(options.providers)) as any
|
||||
case "session":
|
||||
return (await routes.session({ options, sessionStore })) as any
|
||||
case "session": {
|
||||
const session = await routes.session({ options, sessionStore })
|
||||
if (session.cookies) cookies.push(...session.cookies)
|
||||
return { ...session, cookies } as any
|
||||
}
|
||||
case "csrf":
|
||||
return {
|
||||
headers: [{ key: "Content-Type", value: "application/json" }],
|
||||
|
||||
@@ -71,7 +71,7 @@ export async function getToken<R extends boolean = false>(
|
||||
const {
|
||||
req,
|
||||
secureCookie = process.env.NEXTAUTH_URL?.startsWith("https://") ??
|
||||
!!process.env.VERCEL_URL,
|
||||
!!process.env.VERCEL,
|
||||
cookieName = secureCookie
|
||||
? "__Secure-next-auth.session-token"
|
||||
: "next-auth.session-token",
|
||||
|
||||
@@ -50,7 +50,7 @@ export type NextAuthAction =
|
||||
export interface InternalOptions<T extends ProviderType = any> {
|
||||
providers: InternalProvider[]
|
||||
/**
|
||||
* Parsed from `NEXTAUTH_URL` or `VERCEL_URL`.
|
||||
* Parsed from `NEXTAUTH_URL` or `x-forwarded-host` on Vercel.
|
||||
* @default "http://localhost:3000/api/auth"
|
||||
*/
|
||||
url: InternalUrl
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NextAuthHandler } from "../core"
|
||||
import { setCookie } from "./cookie"
|
||||
import { setCookie, detectHost } from "./utils"
|
||||
|
||||
import type {
|
||||
GetServerSidePropsContext,
|
||||
@@ -21,7 +21,7 @@ async function NextAuthNextHandler(
|
||||
const { nextauth, ...query } = req.query
|
||||
const handler = await NextAuthHandler({
|
||||
req: {
|
||||
host: process.env.NEXTAUTH_URL ?? process.env.VERCEL_URL,
|
||||
host: detectHost(req.headers["x-forwarded-host"]),
|
||||
body: req.body,
|
||||
query,
|
||||
cookies: req.cookies,
|
||||
@@ -87,7 +87,7 @@ export async function getServerSession(
|
||||
const session = await NextAuthHandler<Session | {}>({
|
||||
options,
|
||||
req: {
|
||||
host: process.env.NEXTAUTH_URL ?? process.env.VERCEL_URL,
|
||||
host: detectHost(context.req.headers["x-forwarded-host"]),
|
||||
action: "session",
|
||||
method: "GET",
|
||||
cookies: context.req.cookies,
|
||||
@@ -108,7 +108,7 @@ declare global {
|
||||
namespace NodeJS {
|
||||
interface ProcessEnv {
|
||||
NEXTAUTH_URL?: string
|
||||
VERCEL_URL?: string
|
||||
VERCEL?: "1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,3 +13,11 @@ export function setCookie(res, cookie: Cookie) {
|
||||
setCookieHeader.push(cookieHeader)
|
||||
res.setHeader("Set-Cookie", setCookieHeader)
|
||||
}
|
||||
|
||||
/** Extract the host from the environment */
|
||||
export function detectHost(forwardedHost: any) {
|
||||
// If we detect a Vercel environment, we can trust the host
|
||||
if (process.env.VERCEL) return forwardedHost
|
||||
// If `NEXTAUTH_URL` is `undefined` we fall back to "http://localhost:3000"
|
||||
return process.env.NEXTAUTH_URL
|
||||
}
|
||||
@@ -28,7 +28,7 @@ export default function AzureAD<P extends Record<string, any> = AzureADProfile>(
|
||||
wellKnown: `https://login.microsoftonline.com/${tenant}/v2.0/.well-known/openid-configuration`,
|
||||
authorization: {
|
||||
params: {
|
||||
scope: "User.Read",
|
||||
scope: "openid profile email",
|
||||
},
|
||||
},
|
||||
async profile(profile, tokens) {
|
||||
|
||||
@@ -1,10 +1,21 @@
|
||||
import type { OAuthConfig, OAuthUserConfig } from "."
|
||||
|
||||
export interface GoogleProfile {
|
||||
sub: string
|
||||
name: string
|
||||
aud: string
|
||||
azp: string
|
||||
email: string
|
||||
email_verified: boolean
|
||||
exp: number
|
||||
family_name: string
|
||||
given_name: string
|
||||
hd: string
|
||||
iat: number
|
||||
iss: string
|
||||
jti: string
|
||||
name: string
|
||||
nbf: number
|
||||
picture: string
|
||||
sub: string
|
||||
}
|
||||
|
||||
export default function Google<P extends Record<string, any> = GoogleProfile>(
|
||||
|
||||
Reference in New Issue
Block a user