forked from nextauthjs/next-auth
-
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.
feat(events): use named params for all event callbacks (nextauthjs#2342)
Unified API for all of our user-facing methods. NOTE: `events.error` has been removed. This method has never been called in the core, so it did actually nothing. If you want to log errors to a third-party, check out the [`logger`](https://next-auth.js.org/configuration/options#logger) option instead. BREAKING CHANGE: Two event signatures changed to use named params, `signOut` and `updateUser`: ```diff // [...nextauth].js ... events: { - signOut(tokenOrSession), + signOut({ token, session }), // token if using JWT, session if DB persisted sessions. - updateUser(user) + updateUser({ user }) } ```
- Loading branch information
1 parent
94a6c70
commit 1a2ca77
Showing
14 changed files
with
115 additions
and
150 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
/** Event triggered on successful sign in */ | ||
export async function signIn (message) {} | ||
import { upperSnake } from "../../lib/errors" | ||
|
||
/** Event triggered on sign out */ | ||
export async function signOut (message) {} | ||
|
||
/** Event triggered on user creation */ | ||
export async function createUser (message) {} | ||
|
||
/** Event triggered when a user object is updated */ | ||
export async function updateUser (message) {} | ||
|
||
/** Event triggered when an account is linked to a user */ | ||
export async function linkAccount (message) {} | ||
|
||
/** Event triggered when a session is active */ | ||
export async function session (message) {} | ||
/** @type {import("types").EventCallbacks} */ | ||
export const defaultEvents = { | ||
signIn() {}, | ||
signOut() {}, | ||
createUser() {}, | ||
updateUser() {}, | ||
linkAccount() {}, | ||
session() {}, | ||
} | ||
|
||
/** | ||
* @TODO Event triggered when something goes wrong in an authentication flow | ||
* This event may be fired multiple times when an error occurs | ||
* Wraps an object of methods and adds error handling. | ||
* @param {import("types").EventCallbacks} methods | ||
* @param {import("types").LoggerInstance} logger | ||
* @return {import("types").EventCallbacks} | ||
*/ | ||
export async function error (message) {} | ||
export function withErrorHandling(methods, logger) { | ||
return Object.entries(methods).reduce((acc, [name, method]) => { | ||
acc[name] = async (...args) => { | ||
try { | ||
return await method(...args) | ||
} catch (e) { | ||
logger.error(`${upperSnake(name)}_EVENT_ERROR`, e) | ||
} | ||
} | ||
return acc | ||
}, {}) | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.