nuxt-auth-utils 0.5.34 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/README.md +118 -15
  2. package/dist/module.d.mts +3 -3
  3. package/dist/module.json +4 -1
  4. package/dist/module.mjs +18 -31
  5. package/dist/runtime/app/composables/session.js +3 -2
  6. package/dist/runtime/server/api/session.delete.d.ts +1 -1
  7. package/dist/runtime/server/api/session.delete.js +2 -2
  8. package/dist/runtime/server/api/session.get.d.ts +1 -1
  9. package/dist/runtime/server/api/session.get.js +6 -2
  10. package/dist/runtime/server/lib/atproto/bluesky.d.ts +3 -3
  11. package/dist/runtime/server/lib/atproto/bluesky.js +6 -6
  12. package/dist/runtime/server/lib/oauth/apple.d.ts +1 -1
  13. package/dist/runtime/server/lib/oauth/apple.js +3 -4
  14. package/dist/runtime/server/lib/oauth/atlassian.d.ts +1 -1
  15. package/dist/runtime/server/lib/oauth/atlassian.js +8 -8
  16. package/dist/runtime/server/lib/oauth/auth0.d.ts +1 -1
  17. package/dist/runtime/server/lib/oauth/auth0.js +4 -4
  18. package/dist/runtime/server/lib/oauth/authentik.d.ts +1 -1
  19. package/dist/runtime/server/lib/oauth/authentik.js +6 -6
  20. package/dist/runtime/server/lib/oauth/azureb2c.d.ts +1 -1
  21. package/dist/runtime/server/lib/oauth/azureb2c.js +5 -5
  22. package/dist/runtime/server/lib/oauth/battledotnet.d.ts +1 -1
  23. package/dist/runtime/server/lib/oauth/battledotnet.js +6 -6
  24. package/dist/runtime/server/lib/oauth/box.d.ts +1 -1
  25. package/dist/runtime/server/lib/oauth/box.js +5 -5
  26. package/dist/runtime/server/lib/oauth/cloudflare.d.ts +1 -1
  27. package/dist/runtime/server/lib/oauth/cloudflare.js +5 -5
  28. package/dist/runtime/server/lib/oauth/cognito.d.ts +1 -1
  29. package/dist/runtime/server/lib/oauth/cognito.js +4 -4
  30. package/dist/runtime/server/lib/oauth/discord.d.ts +1 -1
  31. package/dist/runtime/server/lib/oauth/discord.js +4 -4
  32. package/dist/runtime/server/lib/oauth/dropbox.d.ts +1 -1
  33. package/dist/runtime/server/lib/oauth/dropbox.js +5 -5
  34. package/dist/runtime/server/lib/oauth/facebook.d.ts +1 -1
  35. package/dist/runtime/server/lib/oauth/facebook.js +7 -7
  36. package/dist/runtime/server/lib/oauth/gitea.d.ts +1 -1
  37. package/dist/runtime/server/lib/oauth/gitea.js +5 -5
  38. package/dist/runtime/server/lib/oauth/github.d.ts +1 -1
  39. package/dist/runtime/server/lib/oauth/github.js +6 -6
  40. package/dist/runtime/server/lib/oauth/gitlab.d.ts +1 -1
  41. package/dist/runtime/server/lib/oauth/gitlab.js +5 -5
  42. package/dist/runtime/server/lib/oauth/google.d.ts +1 -1
  43. package/dist/runtime/server/lib/oauth/google.js +4 -4
  44. package/dist/runtime/server/lib/oauth/heroku.d.ts +1 -1
  45. package/dist/runtime/server/lib/oauth/heroku.js +5 -5
  46. package/dist/runtime/server/lib/oauth/hubspot.d.ts +1 -1
  47. package/dist/runtime/server/lib/oauth/hubspot.js +4 -4
  48. package/dist/runtime/server/lib/oauth/instagram.d.ts +1 -1
  49. package/dist/runtime/server/lib/oauth/instagram.js +6 -6
  50. package/dist/runtime/server/lib/oauth/keycloak.d.ts +1 -1
  51. package/dist/runtime/server/lib/oauth/keycloak.js +6 -6
  52. package/dist/runtime/server/lib/oauth/kick.d.ts +1 -1
  53. package/dist/runtime/server/lib/oauth/kick.js +5 -5
  54. package/dist/runtime/server/lib/oauth/line.d.ts +1 -1
  55. package/dist/runtime/server/lib/oauth/line.js +6 -6
  56. package/dist/runtime/server/lib/oauth/linear.d.ts +1 -1
  57. package/dist/runtime/server/lib/oauth/linear.js +6 -6
  58. package/dist/runtime/server/lib/oauth/linkedin.d.ts +1 -1
  59. package/dist/runtime/server/lib/oauth/linkedin.js +4 -4
  60. package/dist/runtime/server/lib/oauth/livechat.d.ts +1 -1
  61. package/dist/runtime/server/lib/oauth/livechat.js +4 -4
  62. package/dist/runtime/server/lib/oauth/mastodon.d.ts +1 -1
  63. package/dist/runtime/server/lib/oauth/mastodon.js +10 -11
  64. package/dist/runtime/server/lib/oauth/microsoft.d.ts +1 -1
  65. package/dist/runtime/server/lib/oauth/microsoft.js +5 -5
  66. package/dist/runtime/server/lib/oauth/oidc.d.ts +1 -1
  67. package/dist/runtime/server/lib/oauth/oidc.js +6 -6
  68. package/dist/runtime/server/lib/oauth/okta.d.ts +4 -4
  69. package/dist/runtime/server/lib/oauth/okta.js +8 -8
  70. package/dist/runtime/server/lib/oauth/ory.d.ts +1 -1
  71. package/dist/runtime/server/lib/oauth/ory.js +6 -6
  72. package/dist/runtime/server/lib/oauth/osu.d.ts +1 -1
  73. package/dist/runtime/server/lib/oauth/osu.js +4 -4
  74. package/dist/runtime/server/lib/oauth/paypal.d.ts +1 -1
  75. package/dist/runtime/server/lib/oauth/paypal.js +5 -5
  76. package/dist/runtime/server/lib/oauth/polar.d.ts +1 -1
  77. package/dist/runtime/server/lib/oauth/polar.js +5 -5
  78. package/dist/runtime/server/lib/oauth/riotgames.d.ts +1 -1
  79. package/dist/runtime/server/lib/oauth/riotgames.js +5 -5
  80. package/dist/runtime/server/lib/oauth/roblox.d.ts +1 -1
  81. package/dist/runtime/server/lib/oauth/roblox.js +4 -4
  82. package/dist/runtime/server/lib/oauth/salesforce.d.ts +1 -1
  83. package/dist/runtime/server/lib/oauth/salesforce.js +5 -5
  84. package/dist/runtime/server/lib/oauth/seznam.d.ts +1 -1
  85. package/dist/runtime/server/lib/oauth/seznam.js +4 -4
  86. package/dist/runtime/server/lib/oauth/shopifyCustomer.d.ts +1 -1
  87. package/dist/runtime/server/lib/oauth/shopifyCustomer.js +7 -7
  88. package/dist/runtime/server/lib/oauth/slack.d.ts +1 -1
  89. package/dist/runtime/server/lib/oauth/slack.js +5 -5
  90. package/dist/runtime/server/lib/oauth/spotify.d.ts +1 -1
  91. package/dist/runtime/server/lib/oauth/spotify.js +4 -4
  92. package/dist/runtime/server/lib/oauth/steam.d.ts +1 -1
  93. package/dist/runtime/server/lib/oauth/steam.js +9 -9
  94. package/dist/runtime/server/lib/oauth/strava.d.ts +1 -1
  95. package/dist/runtime/server/lib/oauth/strava.js +5 -5
  96. package/dist/runtime/server/lib/oauth/tiktok.d.ts +1 -1
  97. package/dist/runtime/server/lib/oauth/tiktok.js +5 -5
  98. package/dist/runtime/server/lib/oauth/twitch.d.ts +1 -1
  99. package/dist/runtime/server/lib/oauth/twitch.js +5 -5
  100. package/dist/runtime/server/lib/oauth/vk.d.ts +1 -1
  101. package/dist/runtime/server/lib/oauth/vk.js +5 -5
  102. package/dist/runtime/server/lib/oauth/wechat.d.ts +1 -1
  103. package/dist/runtime/server/lib/oauth/wechat.js +7 -7
  104. package/dist/runtime/server/lib/oauth/workos.d.ts +1 -1
  105. package/dist/runtime/server/lib/oauth/workos.js +3 -4
  106. package/dist/runtime/server/lib/oauth/x.d.ts +1 -1
  107. package/dist/runtime/server/lib/oauth/x.js +4 -4
  108. package/dist/runtime/server/lib/oauth/xsuaa.d.ts +1 -1
  109. package/dist/runtime/server/lib/oauth/xsuaa.js +4 -4
  110. package/dist/runtime/server/lib/oauth/yandex.d.ts +1 -1
  111. package/dist/runtime/server/lib/oauth/yandex.js +4 -4
  112. package/dist/runtime/server/lib/oauth/zendesk.d.ts +1 -1
  113. package/dist/runtime/server/lib/oauth/zendesk.js +4 -4
  114. package/dist/runtime/server/lib/oauth/zitadel.d.ts +1 -1
  115. package/dist/runtime/server/lib/oauth/zitadel.js +6 -6
  116. package/dist/runtime/server/lib/session.d.ts +11 -0
  117. package/dist/runtime/server/lib/session.js +33 -0
  118. package/dist/runtime/server/lib/utils.d.ts +9 -8
  119. package/dist/runtime/server/lib/utils.js +13 -11
  120. package/dist/runtime/server/lib/webauthn/authenticate.d.ts +1 -1
  121. package/dist/runtime/server/lib/webauthn/authenticate.js +8 -9
  122. package/dist/runtime/server/lib/webauthn/register.d.ts +2 -2
  123. package/dist/runtime/server/lib/webauthn/register.js +10 -11
  124. package/dist/runtime/server/plugins/oauth-hash.d.ts +2 -0
  125. package/dist/runtime/server/plugins/oauth-hash.js +8 -0
  126. package/dist/runtime/server/routes/atproto/client-metadata.json.get.d.ts +1 -1
  127. package/dist/runtime/server/routes/atproto/client-metadata.json.get.js +5 -5
  128. package/dist/runtime/server/utils/atproto.d.ts +2 -2
  129. package/dist/runtime/server/utils/atproto.js +3 -4
  130. package/dist/runtime/server/utils/password.js +1 -1
  131. package/dist/runtime/server/utils/session.d.ts +26 -17
  132. package/dist/runtime/server/utils/session.js +49 -29
  133. package/dist/runtime/types/event.d.ts +27 -3
  134. package/dist/runtime/types/index.d.ts +1 -1
  135. package/dist/runtime/types/oauth-config.d.ts +3 -3
  136. package/dist/runtime/types/session.d.ts +5 -2
  137. package/dist/runtime/types/webauthn.d.ts +14 -17
  138. package/package.json +10 -6
  139. package/dist/runtime/server/plugins/oauth.d.ts +0 -2
  140. package/dist/runtime/server/plugins/oauth.js +0 -16
  141. package/dist/runtime/server/plugins/ws.d.ts +0 -2
  142. package/dist/runtime/server/plugins/ws.js +0 -7
@@ -1,11 +1,11 @@
1
- import { eventHandler, getQuery, sendRedirect } from "h3";
1
+ import { defineEventHandler, createError, getQuery, sendRedirect, useRuntimeConfig } from "nuxt/server";
2
+ import { $fetch } from "ofetch";
2
3
  import { withQuery } from "ufo";
3
4
  import { defu } from "defu";
4
5
  import { handleAccessTokenErrorResponse, handleInvalidState, handleMissingConfiguration, getOAuthRedirectURL, requestAccessToken, handlePkceVerifier, handleState } from "../utils.js";
5
- import { useRuntimeConfig, createError } from "#imports";
6
6
  export function defineOAuthKickEventHandler({ config, onSuccess, onError }) {
7
- return eventHandler(async (event) => {
8
- config = defu(config, useRuntimeConfig(event).oauth?.kick, {
7
+ return defineEventHandler(async (event) => {
8
+ config = defu(config, useRuntimeConfig().oauth?.kick, {
9
9
  authorizationURL: "https://id.kick.com/oauth/authorize",
10
10
  tokenURL: "https://id.kick.com/oauth/token"
11
11
  });
@@ -58,7 +58,7 @@ export function defineOAuthKickEventHandler({ config, onSuccess, onError }) {
58
58
  });
59
59
  if (!data || !data.length) {
60
60
  const error = createError({
61
- statusCode: 500,
61
+ status: 500,
62
62
  message: "Could not get Kick user",
63
63
  data: tokens
64
64
  });
@@ -42,4 +42,4 @@ export interface OAuthLineConfig {
42
42
  */
43
43
  redirectURL?: string;
44
44
  }
45
- export declare function defineOAuthLineEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthLineConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
45
+ export declare function defineOAuthLineEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthLineConfig>): import("nuxt/server").EventHandler<Promise<any>>;
@@ -1,15 +1,15 @@
1
- import { eventHandler, getQuery, sendRedirect, createError } from "h3";
1
+ import { defineEventHandler, createError, getQuery, sendRedirect, useRuntimeConfig } from "nuxt/server";
2
+ import { $fetch } from "ofetch";
2
3
  import { withQuery } from "ufo";
3
4
  import { defu } from "defu";
4
5
  import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, handleInvalidState, handleState, requestAccessToken } from "../utils.js";
5
- import { useRuntimeConfig } from "#imports";
6
6
  export function defineOAuthLineEventHandler({
7
7
  config,
8
8
  onSuccess,
9
9
  onError
10
10
  }) {
11
- return eventHandler(async (event) => {
12
- config = defu(config, useRuntimeConfig(event).oauth?.line, {
11
+ return defineEventHandler(async (event) => {
12
+ config = defu(config, useRuntimeConfig().oauth?.line, {
13
13
  authorizationURL: "https://access.line.me/oauth2/v2.1/authorize",
14
14
  tokenURL: "https://api.line.me/oauth2/v2.1/token",
15
15
  userURL: "https://api.line.me/v2/profile",
@@ -18,7 +18,7 @@ export function defineOAuthLineEventHandler({
18
18
  const query = getQuery(event);
19
19
  if (query.error) {
20
20
  const error = createError({
21
- statusCode: 401,
21
+ status: 401,
22
22
  message: `Line login failed: ${query.error || "Unknown error"}`,
23
23
  data: query
24
24
  });
@@ -67,7 +67,7 @@ export function defineOAuthLineEventHandler({
67
67
  });
68
68
  if (!user) {
69
69
  const error = createError({
70
- statusCode: 500,
70
+ status: 500,
71
71
  message: "Could not get Line user",
72
72
  data: tokens
73
73
  });
@@ -38,4 +38,4 @@ export interface OAuthLinearConfig {
38
38
  */
39
39
  redirectURL?: string;
40
40
  }
41
- export declare function defineOAuthLinearEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthLinearConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
41
+ export declare function defineOAuthLinearEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthLinearConfig>): import("nuxt/server").EventHandler<Promise<any>>;
@@ -1,11 +1,11 @@
1
- import { eventHandler, getQuery, sendRedirect } from "h3";
1
+ import { defineEventHandler, createError, getQuery, sendRedirect, useRuntimeConfig } from "nuxt/server";
2
+ import { $fetch } from "ofetch";
2
3
  import { withQuery } from "ufo";
3
4
  import { defu } from "defu";
4
5
  import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, handleInvalidState, handleState, requestAccessToken } from "../utils.js";
5
- import { useRuntimeConfig, createError } from "#imports";
6
6
  export function defineOAuthLinearEventHandler({ config, onSuccess, onError }) {
7
- return eventHandler(async (event) => {
8
- config = defu(config, useRuntimeConfig(event).oauth?.linear, {
7
+ return defineEventHandler(async (event) => {
8
+ config = defu(config, useRuntimeConfig().oauth?.linear, {
9
9
  authorizationURL: "https://linear.app/oauth/authorize",
10
10
  tokenURL: "https://api.linear.app/oauth/token",
11
11
  authorizationParams: {}
@@ -13,7 +13,7 @@ export function defineOAuthLinearEventHandler({ config, onSuccess, onError }) {
13
13
  const query = getQuery(event);
14
14
  if (query.error) {
15
15
  const error = createError({
16
- statusCode: 401,
16
+ status: 401,
17
17
  message: `Linear login failed: ${query.error || "Unknown error"}`,
18
18
  data: query
19
19
  });
@@ -70,7 +70,7 @@ export function defineOAuthLinearEventHandler({ config, onSuccess, onError }) {
70
70
  });
71
71
  if (!user.data || !user.data.viewer) {
72
72
  const error = createError({
73
- statusCode: 500,
73
+ status: 500,
74
74
  message: "Could not get Linear user",
75
75
  data: tokens
76
76
  });
@@ -42,4 +42,4 @@ export interface OAuthLinkedInConfig {
42
42
  */
43
43
  redirectURL?: string;
44
44
  }
45
- export declare function defineOAuthLinkedInEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthLinkedInConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
45
+ export declare function defineOAuthLinkedInEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthLinkedInConfig>): import("nuxt/server").EventHandler<Promise<any>>;
@@ -1,11 +1,11 @@
1
- import { eventHandler, getQuery, sendRedirect } from "h3";
1
+ import { defineEventHandler, getQuery, sendRedirect, useRuntimeConfig } from "nuxt/server";
2
+ import { $fetch } from "ofetch";
2
3
  import { withQuery } from "ufo";
3
4
  import { defu } from "defu";
4
5
  import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, handleInvalidState, handleState, requestAccessToken } from "../utils.js";
5
- import { useRuntimeConfig } from "#imports";
6
6
  export function defineOAuthLinkedInEventHandler({ config, onSuccess, onError }) {
7
- return eventHandler(async (event) => {
8
- config = defu(config, useRuntimeConfig(event).oauth?.linkedin, {
7
+ return defineEventHandler(async (event) => {
8
+ config = defu(config, useRuntimeConfig().oauth?.linkedin, {
9
9
  authorizationURL: "https://www.linkedin.com/oauth/v2/authorization",
10
10
  tokenURL: "https://www.linkedin.com/oauth/v2/accessToken",
11
11
  authorizationParams: {}
@@ -70,4 +70,4 @@ export interface LiveChatConfig {
70
70
  */
71
71
  authorizationParams?: Record<string, string>;
72
72
  }
73
- export declare function defineOAuthLiveChatEventHandler({ config, onSuccess, onError, }: OAuthConfig<LiveChatConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
73
+ export declare function defineOAuthLiveChatEventHandler({ config, onSuccess, onError, }: OAuthConfig<LiveChatConfig>): import("nuxt/server").EventHandler<Promise<any>>;
@@ -1,4 +1,5 @@
1
- import { eventHandler, getQuery, sendRedirect } from "h3";
1
+ import { defineEventHandler, getQuery, sendRedirect, useRuntimeConfig } from "nuxt/server";
2
+ import { $fetch } from "ofetch";
2
3
  import { defu } from "defu";
3
4
  import { withQuery } from "ufo";
4
5
  import {
@@ -9,14 +10,13 @@ import {
9
10
  handleState,
10
11
  requestAccessToken
11
12
  } from "../utils.js";
12
- import { useRuntimeConfig } from "#imports";
13
13
  export function defineOAuthLiveChatEventHandler({
14
14
  config,
15
15
  onSuccess,
16
16
  onError
17
17
  }) {
18
- return eventHandler(async (event) => {
19
- config = defu(config, useRuntimeConfig(event).oauth?.livechat, {
18
+ return defineEventHandler(async (event) => {
19
+ config = defu(config, useRuntimeConfig().oauth?.livechat, {
20
20
  authorizationURL: "https://accounts.livechat.com",
21
21
  tokenURL: "https://accounts.livechat.com/v2/token",
22
22
  userURL: "https://accounts.livechat.com/v2/accounts/me",
@@ -58,5 +58,5 @@ interface MastodonTokens {
58
58
  export declare function defineOAuthMastodonEventHandler<TUser = OAuthMastodonUser>({ config: userConfig, onSuccess, onError }: OAuthConfig<OAuthMastodonConfig, {
59
59
  user: TUser;
60
60
  tokens: MastodonTokens;
61
- }>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
61
+ }>): import("nuxt/server").EventHandler<Promise<any>>;
62
62
  export {};
@@ -1,9 +1,8 @@
1
- import { createError, deleteCookie, eventHandler, getCookie, getQuery, sendRedirect, setCookie } from "h3";
1
+ import { createError, defineEventHandler, deleteCookie, getCookie, getQuery, sendRedirect, setCookie, useRuntimeConfig } from "nuxt/server";
2
2
  import { withQuery } from "ufo";
3
3
  import { defu } from "defu";
4
4
  import { $fetch } from "ofetch";
5
- import { getOAuthRedirectURL, handleAccessTokenErrorResponse, handleInvalidState, handleState, isDevelopment, requestAccessToken } from "../utils.js";
6
- import { useRuntimeConfig } from "#imports";
5
+ import { getOAuthRedirectURL, handleAccessTokenErrorResponse, handleInvalidState, handleState, isOAuthCookieSecure, requestAccessToken } from "../utils.js";
7
6
  const FLOW_COOKIE_NAME = "nuxt-auth-mastodon-flow";
8
7
  const appRegistry = /* @__PURE__ */ new Map();
9
8
  const pendingRegistrations = /* @__PURE__ */ new Map();
@@ -64,15 +63,15 @@ async function getOrRegisterApp(instance, redirectURL, scope, clientName) {
64
63
  return registration;
65
64
  }
66
65
  export function defineOAuthMastodonEventHandler({ config: userConfig, onSuccess, onError }) {
67
- return eventHandler(async (event) => {
68
- const config = defu({}, userConfig, useRuntimeConfig(event).oauth?.mastodon, {
66
+ return defineEventHandler(async (event) => {
67
+ const config = defu({}, userConfig, useRuntimeConfig().oauth?.mastodon, {
69
68
  clientName: "Nuxt Auth Utils"
70
69
  });
71
70
  config.scope ||= ["read"];
72
71
  const query = getQuery(event);
73
72
  if (query.error) {
74
73
  const error = createError({
75
- statusCode: 401,
74
+ status: 401,
76
75
  message: `Mastodon login failed: ${query.error || "Unknown error"}`,
77
76
  data: query
78
77
  });
@@ -86,7 +85,7 @@ export function defineOAuthMastodonEventHandler({ config: userConfig, onSuccess,
86
85
  const rawInstance = query.instance?.toString() || config.instance;
87
86
  if (!rawInstance) {
88
87
  const error = createError({
89
- statusCode: 400,
88
+ status: 400,
90
89
  message: "Mastodon login failed: missing instance. Provide it via the `instance` query parameter (e.g. `/auth/mastodon?instance=mastodon.social`), a full handle (`@user@mastodon.social`), or the `instance` config/`NUXT_OAUTH_MASTODON_INSTANCE` env variable."
91
90
  });
92
91
  if (!onError) throw error;
@@ -95,7 +94,7 @@ export function defineOAuthMastodonEventHandler({ config: userConfig, onSuccess,
95
94
  const instance2 = resolveInstanceDomain(rawInstance);
96
95
  if (!isPubliclyAddressableInstance(instance2)) {
97
96
  const error = createError({
98
- statusCode: 400,
97
+ status: 400,
99
98
  message: `Mastodon login failed: "${instance2}" is not a valid instance domain.`
100
99
  });
101
100
  if (!onError) throw error;
@@ -106,7 +105,7 @@ export function defineOAuthMastodonEventHandler({ config: userConfig, onSuccess,
106
105
  app = await getOrRegisterApp(instance2, redirectURL, scope, config.clientName || "Nuxt Auth Utils");
107
106
  } catch {
108
107
  const error = createError({
109
- statusCode: 500,
108
+ status: 500,
110
109
  message: `Mastodon login failed: could not register the application with instance "${instance2}". Make sure it is a reachable Mastodon (or compatible) server.`
111
110
  });
112
111
  if (!onError) throw error;
@@ -115,7 +114,7 @@ export function defineOAuthMastodonEventHandler({ config: userConfig, onSuccess,
115
114
  const flowState2 = { instance: instance2, clientId: app.client_id, clientSecret: app.client_secret };
116
115
  setCookie(event, FLOW_COOKIE_NAME, btoa(JSON.stringify(flowState2)), {
117
116
  httpOnly: true,
118
- secure: !isDevelopment,
117
+ secure: isOAuthCookieSecure(),
119
118
  sameSite: "lax",
120
119
  maxAge: 60 * 10,
121
120
  path: "/"
@@ -141,7 +140,7 @@ export function defineOAuthMastodonEventHandler({ config: userConfig, onSuccess,
141
140
  }
142
141
  if (!flowState || !isPubliclyAddressableInstance(flowState.instance)) {
143
142
  const error = createError({
144
- statusCode: 400,
143
+ status: 400,
145
144
  message: "Mastodon login failed: could not recover the application credentials for this login (missing or invalid flow cookie, the flow may have taken too long or cookies are blocked)."
146
145
  });
147
146
  if (!onError) throw error;
@@ -51,4 +51,4 @@ export interface OAuthMicrosoftConfig {
51
51
  */
52
52
  redirectURL?: string;
53
53
  }
54
- export declare function defineOAuthMicrosoftEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthMicrosoftConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
54
+ export declare function defineOAuthMicrosoftEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthMicrosoftConfig>): import("nuxt/server").EventHandler<Promise<any>>;
@@ -1,11 +1,11 @@
1
- import { eventHandler, getQuery, sendRedirect } from "h3";
1
+ import { defineEventHandler, createError, getQuery, sendRedirect, useRuntimeConfig } from "nuxt/server";
2
+ import { $fetch } from "ofetch";
2
3
  import { withQuery } from "ufo";
3
4
  import { defu } from "defu";
4
5
  import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, handleInvalidState, handleState, requestAccessToken } from "../utils.js";
5
- import { useRuntimeConfig, createError } from "#imports";
6
6
  export function defineOAuthMicrosoftEventHandler({ config, onSuccess, onError }) {
7
- return eventHandler(async (event) => {
8
- config = defu(config, useRuntimeConfig(event).oauth?.microsoft, {
7
+ return defineEventHandler(async (event) => {
8
+ config = defu(config, useRuntimeConfig().oauth?.microsoft, {
9
9
  authorizationParams: {}
10
10
  });
11
11
  const query = getQuery(event);
@@ -58,7 +58,7 @@ export function defineOAuthMicrosoftEventHandler({ config, onSuccess, onError })
58
58
  });
59
59
  if (user.error) {
60
60
  const error = createError({
61
- statusCode: 401,
61
+ status: 401,
62
62
  message: `Microsoft login failed: ${user.error || "Unknown error"}`,
63
63
  data: user
64
64
  });
@@ -211,5 +211,5 @@ interface OIDCConfiguration {
211
211
  export declare function defineOAuthOidcEventHandler<TUser = OidcUser>({ config, onSuccess, onError }: OAuthConfig<OAuthOidcConfig, {
212
212
  user: TUser;
213
213
  tokens: OidcTokens;
214
- }>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
214
+ }>): import("nuxt/server").EventHandler<Promise<any>>;
215
215
  export {};
@@ -1,15 +1,15 @@
1
- import { useRuntimeConfig } from "#imports";
1
+ import { defineEventHandler, createError, getQuery, sendRedirect, useRuntimeConfig } from "nuxt/server";
2
+ import { $fetch } from "ofetch";
2
3
  import { defu } from "defu";
3
- import { createError, eventHandler, getQuery, sendRedirect } from "h3";
4
4
  import { withQuery } from "ufo";
5
5
  import { getOAuthRedirectURL, handleAccessTokenErrorResponse, handleInvalidState, handleMissingConfiguration, handlePkceVerifier, handleState, requestAccessToken, handleNonce, parseJwt } from "../utils.js";
6
6
  export function defineOAuthOidcEventHandler({ config, onSuccess, onError }) {
7
- return eventHandler(async (event) => {
8
- config = defu(config, useRuntimeConfig(event).oauth.oidc);
7
+ return defineEventHandler(async (event) => {
8
+ config = defu(config, useRuntimeConfig().oauth.oidc);
9
9
  const query = getQuery(event);
10
10
  if (query.error) {
11
11
  const error = createError({
12
- statusCode: 401,
12
+ status: 401,
13
13
  message: `OIDC login failed: ${query.error || "Unknown error"}`,
14
14
  data: query
15
15
  });
@@ -67,7 +67,7 @@ export function defineOAuthOidcEventHandler({ config, onSuccess, onError }) {
67
67
  const claims = parseJwt(tokens.id_token);
68
68
  if (claims.nonce !== nonce) {
69
69
  const error = createError({
70
- statusCode: 401,
70
+ status: 401,
71
71
  message: "OIDC login failed: nonce mismatch"
72
72
  });
73
73
  if (!onError) throw error;
@@ -1,4 +1,4 @@
1
- import type { H3Event } from 'h3';
1
+ import type { RequestEvent } from 'nuxt/server';
2
2
  import type { OAuthConfig } from '#auth-utils';
3
3
  export interface OpenIdConfig {
4
4
  authorization_endpoint: string;
@@ -13,8 +13,8 @@ export interface OAuthConfigExt<TConfig, TResult = {
13
13
  openIdConfig: OpenIdConfig;
14
14
  }> extends OAuthConfig<TConfig, TResult> {
15
15
  config?: TConfig;
16
- onSuccess: (event: H3Event, result: TResult) => Promise<void> | void;
17
- onError?: (event: H3Event, error: unknown) => Promise<void> | void;
16
+ onSuccess: (event: RequestEvent, result: TResult) => unknown;
17
+ onError?: (event: RequestEvent, error: unknown) => unknown;
18
18
  }
19
19
  export interface OAuthOktaConfig {
20
20
  /**
@@ -85,4 +85,4 @@ export interface OAuthOktaConfig {
85
85
  */
86
86
  openIdConfigCacheTTL?: number;
87
87
  }
88
- export declare function defineOAuthOktaEventHandler({ config, onSuccess, onError }: OAuthConfigExt<OAuthOktaConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
88
+ export declare function defineOAuthOktaEventHandler({ config, onSuccess, onError }: OAuthConfigExt<OAuthOktaConfig>): import("nuxt/server").EventHandler<Promise<any>>;
@@ -1,8 +1,8 @@
1
- import { eventHandler, getQuery, sendRedirect, createError } from "h3";
1
+ import { defineEventHandler, createError, getQuery, sendRedirect, useRuntimeConfig } from "nuxt/server";
2
+ import { $fetch } from "ofetch";
2
3
  import { withQuery } from "ufo";
3
4
  import { defu } from "defu";
4
5
  import { handleMissingConfiguration, handleState, handleInvalidState, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken } from "../utils.js";
5
- import { useRuntimeConfig } from "#imports";
6
6
  const openIdConfigCache = /* @__PURE__ */ new Map();
7
7
  const DEFAULT_CACHE_TTL = 1e3 * 60 * 60 * 24;
8
8
  export function defineOAuthOktaEventHandler({ config, onSuccess, onError }) {
@@ -23,8 +23,8 @@ export function defineOAuthOktaEventHandler({ config, onSuccess, onError }) {
23
23
  }
24
24
  return result;
25
25
  }
26
- return eventHandler(async (event) => {
27
- const runtimeConfig = useRuntimeConfig(event);
26
+ return defineEventHandler(async (event) => {
27
+ const runtimeConfig = useRuntimeConfig();
28
28
  config = defu(config, runtimeConfig.oauth?.okta, {
29
29
  authorizationParams: {}
30
30
  });
@@ -34,7 +34,7 @@ export function defineOAuthOktaEventHandler({ config, onSuccess, onError }) {
34
34
  const query = getQuery(event);
35
35
  if (query.error) {
36
36
  const error = createError({
37
- statusCode: 401,
37
+ status: 401,
38
38
  message: `Okta login failed: ${query.error || "Unknown error"} - ${query.error_description || ""}`,
39
39
  data: query
40
40
  });
@@ -79,7 +79,7 @@ export function defineOAuthOktaEventHandler({ config, onSuccess, onError }) {
79
79
  } else {
80
80
  console.error("Failed to fetch Okta OpenID configuration. Please check your Okta domain and network connectivity:", error);
81
81
  const err = createError({
82
- statusCode: 500,
82
+ status: 500,
83
83
  message: "Could not get Okta OpenID configuration. Please verify that your Okta domain is correct and reachable, and that the OpenID configuration endpoint is accessible.",
84
84
  data: error
85
85
  });
@@ -136,7 +136,7 @@ export function defineOAuthOktaEventHandler({ config, onSuccess, onError }) {
136
136
  }
137
137
  if (!tokens.access_token || typeof tokens.access_token !== "string" || !tokens.token_type || typeof tokens.token_type !== "string") {
138
138
  const err = createError({
139
- statusCode: 400,
139
+ status: 400,
140
140
  message: "Invalid token response from Okta",
141
141
  data: tokens
142
142
  });
@@ -154,7 +154,7 @@ export function defineOAuthOktaEventHandler({ config, onSuccess, onError }) {
154
154
  });
155
155
  } catch (error) {
156
156
  const err = createError({
157
- statusCode: 410,
157
+ status: 410,
158
158
  message: `Could not get Okta user info - ${error instanceof Error ? error.message : String(error)}`,
159
159
  data: tokens
160
160
  });
@@ -48,4 +48,4 @@ export interface OAuthOryConfig {
48
48
  */
49
49
  userURL?: string;
50
50
  }
51
- export declare function defineOAuthOryEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthOryConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
51
+ export declare function defineOAuthOryEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthOryConfig>): import("nuxt/server").EventHandler<Promise<any>>;
@@ -1,4 +1,5 @@
1
- import { eventHandler, getQuery, sendRedirect } from "h3";
1
+ import { defineEventHandler, createError, getQuery, sendRedirect, useRuntimeConfig } from "nuxt/server";
2
+ import { $fetch } from "ofetch";
2
3
  import { withQuery } from "ufo";
3
4
  import { defu } from "defu";
4
5
  import {
@@ -10,10 +11,9 @@ import {
10
11
  handleState,
11
12
  requestAccessToken
12
13
  } from "../utils.js";
13
- import { createError, useRuntimeConfig } from "#imports";
14
14
  export function defineOAuthOryEventHandler({ config, onSuccess, onError }) {
15
- return eventHandler(async (event) => {
16
- config = defu(config, useRuntimeConfig(event).oauth?.ory, {
15
+ return defineEventHandler(async (event) => {
16
+ config = defu(config, useRuntimeConfig().oauth?.ory, {
17
17
  scope: ["openid", "offline"],
18
18
  sdkURL: "https://playground.projects.oryapis.com",
19
19
  authorizationURL: "/oauth2/auth",
@@ -24,7 +24,7 @@ export function defineOAuthOryEventHandler({ config, onSuccess, onError }) {
24
24
  const query = getQuery(event);
25
25
  if (query.error) {
26
26
  const error = createError({
27
- statusCode: 401,
27
+ status: 401,
28
28
  message: `Ory login failed: ${query.error || "Unknown error"}`,
29
29
  data: query
30
30
  });
@@ -86,7 +86,7 @@ export function defineOAuthOryEventHandler({ config, onSuccess, onError }) {
86
86
  });
87
87
  if (user.error) {
88
88
  const error = createError({
89
- statusCode: 401,
89
+ status: 401,
90
90
  message: `Ory userinfo failed: ${user.error || "Unknown error"}`,
91
91
  data: user
92
92
  });
@@ -39,4 +39,4 @@ export interface OAuthOsuConfig {
39
39
  */
40
40
  redirectURL?: string;
41
41
  }
42
- export declare function defineOAuthOsuEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthOsuConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
42
+ export declare function defineOAuthOsuEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthOsuConfig>): import("nuxt/server").EventHandler<Promise<any>>;
@@ -1,11 +1,11 @@
1
- import { eventHandler, getQuery, sendRedirect } from "h3";
1
+ import { defineEventHandler, getQuery, sendRedirect, useRuntimeConfig } from "nuxt/server";
2
+ import { $fetch } from "ofetch";
2
3
  import { withQuery } from "ufo";
3
4
  import { defu } from "defu";
4
5
  import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, requestAccessToken, handleState, handleInvalidState } from "../utils.js";
5
- import { useRuntimeConfig } from "#imports";
6
6
  export function defineOAuthOsuEventHandler({ config, onSuccess, onError }) {
7
- return eventHandler(async (event) => {
8
- config = defu(config, useRuntimeConfig(event).oauth?.osu, {
7
+ return defineEventHandler(async (event) => {
8
+ config = defu(config, useRuntimeConfig().oauth?.osu, {
9
9
  authorizationURL: "https://osu.ppy.sh/oauth/authorize",
10
10
  tokenURL: "https://osu.ppy.sh/oauth/token",
11
11
  authorizationParams: {}
@@ -49,4 +49,4 @@ export interface OAuthPaypalConfig {
49
49
  */
50
50
  redirectURL?: string;
51
51
  }
52
- export declare function defineOAuthPaypalEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthPaypalConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
52
+ export declare function defineOAuthPaypalEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthPaypalConfig>): import("nuxt/server").EventHandler<Promise<any>>;
@@ -1,11 +1,11 @@
1
- import { eventHandler, getQuery, sendRedirect } from "h3";
1
+ import { defineEventHandler, createError, getQuery, sendRedirect, useRuntimeConfig } from "nuxt/server";
2
+ import { $fetch } from "ofetch";
2
3
  import { withQuery } from "ufo";
3
4
  import { defu } from "defu";
4
5
  import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, handleInvalidState, handleState, requestAccessToken } from "../utils.js";
5
- import { useRuntimeConfig, createError } from "#imports";
6
6
  export function defineOAuthPaypalEventHandler({ config, onSuccess, onError }) {
7
- return eventHandler(async (event) => {
8
- config = defu(config, useRuntimeConfig(event).oauth?.paypal, {
7
+ return defineEventHandler(async (event) => {
8
+ config = defu(config, useRuntimeConfig().oauth?.paypal, {
9
9
  sandbox: import.meta.dev,
10
10
  authorizationURL: "https://www.paypal.com/signin/authorize",
11
11
  tokenURL: "https://api-m.paypal.com/v1/oauth2/token",
@@ -74,7 +74,7 @@ export function defineOAuthPaypalEventHandler({ config, onSuccess, onError }) {
74
74
  const user = users;
75
75
  if (!user) {
76
76
  const error = createError({
77
- statusCode: 500,
77
+ status: 500,
78
78
  message: "Could not get PayPal user",
79
79
  data: tokens
80
80
  });
@@ -46,4 +46,4 @@ export interface OAuthPolarConfig {
46
46
  */
47
47
  redirectURL?: string;
48
48
  }
49
- export declare function defineOAuthPolarEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthPolarConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
49
+ export declare function defineOAuthPolarEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthPolarConfig>): import("nuxt/server").EventHandler<Promise<any>>;
@@ -1,11 +1,11 @@
1
- import { eventHandler, getQuery, sendRedirect } from "h3";
1
+ import { defineEventHandler, createError, getQuery, sendRedirect, useRuntimeConfig } from "nuxt/server";
2
+ import { $fetch } from "ofetch";
2
3
  import { withQuery } from "ufo";
3
4
  import { defu } from "defu";
4
5
  import { handleAccessTokenErrorResponse, handleInvalidState, handleMissingConfiguration, getOAuthRedirectURL, handleState, requestAccessToken } from "../utils.js";
5
- import { useRuntimeConfig, createError } from "#imports";
6
6
  export function defineOAuthPolarEventHandler({ config, onSuccess, onError }) {
7
- return eventHandler(async (event) => {
8
- config = defu(config, useRuntimeConfig(event).oauth?.polar, {
7
+ return defineEventHandler(async (event) => {
8
+ config = defu(config, useRuntimeConfig().oauth?.polar, {
9
9
  authorizationURL: "https://polar.sh/oauth2/authorize",
10
10
  tokenURL: "https://api.polar.sh/v1/oauth2/token"
11
11
  });
@@ -57,7 +57,7 @@ export function defineOAuthPolarEventHandler({ config, onSuccess, onError }) {
57
57
  });
58
58
  if (!user) {
59
59
  const error = createError({
60
- statusCode: 500,
60
+ status: 500,
61
61
  message: "Could not get Polar user",
62
62
  data: tokens
63
63
  });
@@ -70,5 +70,5 @@ interface RiotGamesTokens {
70
70
  export declare function defineOAuthRiotGamesEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthRiotGamesConfig, {
71
71
  user: RiotGamesUser;
72
72
  tokens: RiotGamesTokens;
73
- }>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
73
+ }>): import("nuxt/server").EventHandler<Promise<any>>;
74
74
  export {};
@@ -1,11 +1,11 @@
1
- import { createError, eventHandler, getQuery, sendRedirect } from "h3";
1
+ import { defineEventHandler, createError, getQuery, sendRedirect, useRuntimeConfig } from "nuxt/server";
2
+ import { $fetch } from "ofetch";
2
3
  import { withQuery } from "ufo";
3
4
  import { defu } from "defu";
4
5
  import { getOAuthRedirectURL, handleAccessTokenErrorResponse, handleInvalidState, handleMissingConfiguration, handleState, requestAccessToken } from "../utils.js";
5
- import { useRuntimeConfig } from "#imports";
6
6
  export function defineOAuthRiotGamesEventHandler({ config, onSuccess, onError }) {
7
- return eventHandler(async (event) => {
8
- config = defu(config, useRuntimeConfig(event).oauth?.riotgames, {
7
+ return defineEventHandler(async (event) => {
8
+ config = defu(config, useRuntimeConfig().oauth?.riotgames, {
9
9
  authorizationURL: "https://auth.riotgames.com/authorize",
10
10
  tokenURL: "https://auth.riotgames.com/token",
11
11
  apiURL: "https://auth.riotgames.com",
@@ -14,7 +14,7 @@ export function defineOAuthRiotGamesEventHandler({ config, onSuccess, onError })
14
14
  const query = getQuery(event);
15
15
  if (query.error) {
16
16
  const error = createError({
17
- statusCode: 401,
17
+ status: 401,
18
18
  message: `RiotGames login failed: ${query.error || "Unknown error"}`,
19
19
  data: query
20
20
  });
@@ -123,4 +123,4 @@ export interface OAuthRobloxUser {
123
123
  visibility: 'SOCIAL_NETWORK_VISIBILITY_UNSPECIFIED' | 'NO_ONE' | 'FRIENDS' | 'FRIENDS_AND_FOLLOWING' | 'FRIENDS_FOLLOWING_AND_FOLLOWERS' | 'EVERYONE';
124
124
  };
125
125
  }
126
- export declare function defineOAuthRobloxEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthRobloxConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
126
+ export declare function defineOAuthRobloxEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthRobloxConfig>): import("nuxt/server").EventHandler<Promise<any>>;
@@ -1,11 +1,11 @@
1
- import { eventHandler, getQuery, sendRedirect } from "h3";
1
+ import { defineEventHandler, getQuery, sendRedirect, useRuntimeConfig } from "nuxt/server";
2
+ import { $fetch } from "ofetch";
2
3
  import { withQuery } from "ufo";
3
4
  import { defu } from "defu";
4
5
  import { handleMissingConfiguration, handleAccessTokenErrorResponse, getOAuthRedirectURL, handleInvalidState, handleState, requestAccessToken } from "../utils.js";
5
- import { useRuntimeConfig } from "#imports";
6
6
  export function defineOAuthRobloxEventHandler({ config, onSuccess, onError }) {
7
- return eventHandler(async (event) => {
8
- config = defu(config, useRuntimeConfig(event).oauth?.roblox, {
7
+ return defineEventHandler(async (event) => {
8
+ config = defu(config, useRuntimeConfig().oauth?.roblox, {
9
9
  authorizationURL: "https://apis.roblox.com/oauth/v1/authorize",
10
10
  tokenURL: "https://apis.roblox.com/oauth/v1/token",
11
11
  authorizationParams: {}
@@ -48,4 +48,4 @@ export interface OAuthSalesforceConfig {
48
48
  */
49
49
  redirectURL?: string;
50
50
  }
51
- export declare function defineOAuthSalesforceEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthSalesforceConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
51
+ export declare function defineOAuthSalesforceEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthSalesforceConfig>): import("nuxt/server").EventHandler<Promise<any>>;