mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
Compare commits
7 Commits
@next-auth
...
@auth/core
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7c1a3b547e | ||
|
|
2534ae8801 | ||
|
|
14a120277b | ||
|
|
c49f484743 | ||
|
|
676b39d5b1 | ||
|
|
e27dbcab2f | ||
|
|
63805c7d75 |
4
.github/actions/issue-validator/repro.md
vendored
4
.github/actions/issue-validator/repro.md
vendored
@@ -14,9 +14,9 @@ Ensure the link is pointing to a codebase that is accessible (e.g. not a private
|
||||
|
||||
### **What happens if I don't provide a sufficient minimal reproduction?**
|
||||
|
||||
Issues with the `incomplete` label that receives no meaningful activity (e.g. new comments with a reproduction link) are automatically closed and locked after 30 days.
|
||||
Issues with the `incomplete` label that receives no meaningful activity (e.g. new comments with a reproduction link) are closed after 7 days.
|
||||
|
||||
If your issue has _not_ been resolved in that time and it has been closed/locked, please open a new issue with the required reproduction.
|
||||
If your issue has _not_ been resolved in that time and it has been closed/locked, please open a new issue with the required reproduction. (It's less likely that we check back on already closed issues.)
|
||||
|
||||
### **I did not open this issue, but it is relevant to me, what can I do to help?**
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
title: Role-based authentication
|
||||
title: Role-based access control
|
||||
---
|
||||
|
||||
There are two ways to add role-based authentication (RBAC) to your application, based on the [session strategy](/concepts/session-strategies) you choose. Let's see an example for each of these.
|
||||
There are two ways to add role-based access control (RBAC) to your application, based on the [session strategy](/concepts/session-strategies) you choose. Let's see an example for each of these.
|
||||
|
||||
## Getting the role
|
||||
|
||||
@@ -150,4 +150,4 @@ When using Next.js and JWT, you can alternatively also use [Middleware](https://
|
||||
- [Next.js: Middleware](https://next-auth.js.org/configuration/nextjs#wrap-middleware)
|
||||
- [Adapters: User model](/reference/adapters/models#user)
|
||||
- [Adapters: Prisma adapter](/reference/adapters/prisma)
|
||||
- [TypeScript](/getting-started/typescript)
|
||||
- [TypeScript](/getting-started/typescript)
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@auth/core",
|
||||
"version": "0.5.0",
|
||||
"version": "0.5.1",
|
||||
"description": "Authentication for the Web.",
|
||||
"keywords": [
|
||||
"authentication",
|
||||
|
||||
@@ -101,7 +101,7 @@ export async function init({
|
||||
// Asserted in assert.ts
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
secret: authOptions.secret!,
|
||||
maxAge, // same as session maxAge,
|
||||
maxAge: authOptions.session?.maxAge ?? maxAge, // default to same as `session.maxAge`
|
||||
encode: jwt.encode,
|
||||
decode: jwt.decode,
|
||||
...authOptions.jwt,
|
||||
|
||||
@@ -60,7 +60,6 @@ export async function session(
|
||||
const newToken = await jwt.encode({
|
||||
...jwt,
|
||||
token,
|
||||
maxAge: options.session.maxAge,
|
||||
})
|
||||
|
||||
// Set cookie, to also update expiry date on cookie
|
||||
@@ -73,7 +72,7 @@ export async function session(
|
||||
await events.session?.({ session: newSession, token })
|
||||
} else {
|
||||
response.cookies?.push(...sessionStore.clean())
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error(new JWTSessionError(e as Error))
|
||||
// If the JWT is not verifiable remove the broken session cookie(s).
|
||||
|
||||
@@ -129,14 +129,14 @@ export default function GitHub(
|
||||
url: "https://api.github.com/user",
|
||||
async request({ tokens, provider }) {
|
||||
const profile = await fetch(provider.userinfo?.url as URL, {
|
||||
headers: { Authorization: `Bearer ${tokens.access_token}` },
|
||||
headers: { Authorization: `Bearer ${tokens.access_token}`, 'User-Agent': 'authjs' },
|
||||
}).then(async (res) => await res.json())
|
||||
|
||||
if (!profile.email) {
|
||||
// If the user does not have a public email, get another via the GitHub API
|
||||
// See https://docs.github.com/en/rest/users/emails#list-public-email-addresses-for-the-authenticated-user
|
||||
const res = await fetch("https://api.github.com/user/emails", {
|
||||
headers: { Authorization: `Bearer ${tokens.access_token}` },
|
||||
headers: { Authorization: `Bearer ${tokens.access_token}`, 'User-Agent': 'authjs' },
|
||||
})
|
||||
|
||||
if (res.ok) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@auth/sveltekit",
|
||||
"version": "0.2.2",
|
||||
"version": "0.3.0",
|
||||
"description": "Authentication for SvelteKit.",
|
||||
"keywords": [
|
||||
"authentication",
|
||||
|
||||
@@ -26,6 +26,23 @@
|
||||
* providers: [GitHub({ clientId: GITHUB_ID, clientSecret: GITHUB_SECRET })],
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* or to use sveltekit platform environment variables for platforms like Cloudflare
|
||||
*
|
||||
* ```ts title="src/hooks.server.ts"
|
||||
* import { SvelteKitAuth } from "@auth/sveltekit"
|
||||
* import GitHub from "@auth/core/providers/github"
|
||||
* import type { Handle } from "@sveltejs/kit";
|
||||
*
|
||||
* export const handle = SvelteKitAuth(async (event) => {
|
||||
* const authOptions = {
|
||||
* providers: [GitHub({ clientId: event.platform.env.GITHUB_ID, clientSecret: event.platform.env.GITHUB_SECRET })]
|
||||
* secret: event.platform.env.AUTH_SECRET,
|
||||
* trustHost: true
|
||||
* }
|
||||
* return authOptions
|
||||
* }) satisfies Handle;
|
||||
* ```
|
||||
*
|
||||
* Don't forget to set the `AUTH_SECRET` [environment variable](https://kit.svelte.dev/docs/modules#$env-dynamic-private). This should be a minimum of 32 characters, random string. On UNIX systems you can use `openssl rand -hex 32` or check out `https://generate-secret.vercel.app/32`.
|
||||
*
|
||||
@@ -71,7 +88,7 @@
|
||||
* ## Managing the session
|
||||
*
|
||||
* The above example checks for a session available in `$page.data.session`, however that needs to be set by us somewhere.
|
||||
* If you want this data to be available to all your routes you can add this to your root `+layout.server.ts` file.
|
||||
* If you want this data to be available to all your routes you can add this to `src/routes/+layout.server.ts`.
|
||||
* The following code sets the session data in the `$page` store to be available to all routes.
|
||||
*
|
||||
* ```ts
|
||||
@@ -187,7 +204,7 @@
|
||||
*/
|
||||
|
||||
/// <reference types="@sveltejs/kit" />
|
||||
import type { Handle } from "@sveltejs/kit"
|
||||
import type { Handle, RequestEvent } from "@sveltejs/kit"
|
||||
|
||||
import { dev } from "$app/environment"
|
||||
import { env } from "$env/dynamic/private"
|
||||
@@ -237,8 +254,15 @@ const actions: AuthAction[] = [
|
||||
"error",
|
||||
]
|
||||
|
||||
function AuthHandle(prefix: string, authOptions: AuthConfig): Handle {
|
||||
return function ({ event, resolve }) {
|
||||
type DynamicSvelteKitAuthConfig = (event: RequestEvent) => PromiseLike<SvelteKitAuthConfig>
|
||||
|
||||
function AuthHandle(svelteKitAuthOptions: SvelteKitAuthConfig | DynamicSvelteKitAuthConfig): Handle {
|
||||
return async function ({ event, resolve }) {
|
||||
const authOptions =
|
||||
typeof svelteKitAuthOptions === "object"
|
||||
? svelteKitAuthOptions
|
||||
: await svelteKitAuthOptions(event)
|
||||
const { prefix = "/auth" } = authOptions
|
||||
const { url, request } = event
|
||||
|
||||
event.locals.getSession ??= () => getSession(request, authOptions)
|
||||
@@ -259,11 +283,12 @@ function AuthHandle(prefix: string, authOptions: AuthConfig): Handle {
|
||||
* The main entry point to `@auth/sveltekit`
|
||||
* @see https://sveltekit.authjs.dev
|
||||
*/
|
||||
export function SvelteKitAuth(options: SvelteKitAuthConfig): Handle {
|
||||
const { prefix = "/auth", ...authOptions } = options
|
||||
authOptions.secret ??= env.AUTH_SECRET
|
||||
authOptions.trustHost ??= !!(env.AUTH_TRUST_HOST ?? env.VERCEL ?? dev)
|
||||
return AuthHandle(prefix, authOptions)
|
||||
export function SvelteKitAuth(options: SvelteKitAuthConfig | DynamicSvelteKitAuthConfig): Handle {
|
||||
if (typeof options === "object") {
|
||||
options.secret ??= env.AUTH_SECRET
|
||||
options.trustHost ??= !!(env.AUTH_TRUST_HOST ?? env.VERCEL ?? dev)
|
||||
}
|
||||
return AuthHandle(options)
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
Reference in New Issue
Block a user