nuxt-auth-utils 0.5.18 → 0.5.20

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.
package/README.md CHANGED
@@ -253,7 +253,7 @@ It can also be set using environment variables:
253
253
  - Yandex
254
254
  - Zitadel
255
255
 
256
- You can add your favorite provider by creating a new file in [src/runtime/server/lib/oauth/](./src/runtime/server/lib/oauth/).
256
+ You can add your favorite provider by creating a new file in [src/runtime/server/lib/oauth/](https://github.com/atinux/nuxt-auth-utils/tree/main/src/runtime/server/lib/oauth).
257
257
 
258
258
  #### Example
259
259
 
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "auth-utils",
3
3
  "configKey": "auth",
4
- "version": "0.5.18",
4
+ "version": "0.5.20",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
@@ -2,7 +2,7 @@ import { appendResponseHeader } from "h3";
2
2
  import { useState, computed, useRequestFetch, useRequestEvent } from "#imports";
3
3
  export function useUserSession() {
4
4
  const serverEvent = import.meta.server ? useRequestEvent() : null;
5
- const sessionState = useState("nuxt-session", () => ({}));
5
+ const sessionState = useState("nuxt-session", () => null);
6
6
  const authReadyState = useState("nuxt-auth-ready", () => false);
7
7
  const clear = async () => {
8
8
  await useRequestFetch()("/api/_auth/session", {
@@ -15,7 +15,7 @@ export function useUserSession() {
15
15
  }
16
16
  }
17
17
  });
18
- sessionState.value = {};
18
+ sessionState.value = null;
19
19
  };
20
20
  const fetch = async () => {
21
21
  sessionState.value = await useRequestFetch()("/api/_auth/session", {
@@ -23,7 +23,7 @@ export function useUserSession() {
23
23
  accept: "application/json"
24
24
  },
25
25
  retry: false
26
- }).catch(() => ({}));
26
+ }).catch(() => null);
27
27
  if (!authReadyState.value) {
28
28
  authReadyState.value = true;
29
29
  }
@@ -49,8 +49,8 @@ export function useUserSession() {
49
49
  };
50
50
  return {
51
51
  ready: computed(() => authReadyState.value),
52
- loggedIn: computed(() => Boolean(sessionState.value.user)),
53
- user: computed(() => sessionState.value.user || null),
52
+ loggedIn: computed(() => Boolean(sessionState.value?.user)),
53
+ user: computed(() => sessionState.value?.user || null),
54
54
  session: sessionState,
55
55
  fetch,
56
56
  openInPopup,
@@ -1,5 +1,6 @@
1
1
  declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<{
2
- id: any;
2
+ [key: string]: unknown;
3
+ id: string;
3
4
  user?: import("../../types").User;
4
5
  }>>;
5
6
  export default _default;
@@ -19,7 +19,10 @@ export interface OAuthBlueskyConfig {
19
19
  }
20
20
  type BlueSkyUser = AppBskyActorDefs.ProfileViewDetailed | Pick<AppBskyActorDefs.ProfileView, 'did'>;
21
21
  type BlueSkyTokens = NodeSavedSession['tokenSet'];
22
- export declare function defineOAuthBlueskyEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthBlueskyConfig, BlueSkyUser, BlueSkyTokens>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
22
+ export declare function defineOAuthBlueskyEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthBlueskyConfig, {
23
+ user: BlueSkyUser;
24
+ tokens: BlueSkyTokens;
25
+ }>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
23
26
  export declare class StateStore implements NodeSavedStateStore {
24
27
  private event;
25
28
  private readonly stateKey;
@@ -70,4 +70,8 @@ export interface OAuthAppleUser {
70
70
  };
71
71
  email?: string;
72
72
  }
73
- export declare function defineOAuthAppleEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthAppleConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
73
+ export declare function defineOAuthAppleEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthAppleConfig, {
74
+ user: OAuthAppleUser;
75
+ payload: OAuthAppleTokens;
76
+ tokens: any;
77
+ }>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
@@ -7,6 +7,7 @@ export function defineOAuthAppleEventHandler({
7
7
  config,
8
8
  onSuccess,
9
9
  onError
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
11
  }) {
11
12
  return eventHandler(async (event) => {
12
13
  config = defu(config, useRuntimeConfig(event).oauth?.apple, {
@@ -1,4 +1,29 @@
1
1
  import type { OAuthConfig } from '#auth-utils';
2
+ interface AtlassianUser {
3
+ account_id?: string;
4
+ email?: string;
5
+ name?: string;
6
+ picture?: string;
7
+ account_status?: string;
8
+ characteristics?: {
9
+ not_mentionable?: boolean;
10
+ };
11
+ last_updated?: string;
12
+ nickname?: string;
13
+ locale?: string;
14
+ extended_profile?: {
15
+ phone_numbers?: string[];
16
+ };
17
+ account_type?: string;
18
+ email_verified?: boolean;
19
+ }
20
+ interface AtlassianTokens {
21
+ access_token?: string;
22
+ expires_in?: number;
23
+ token_type?: string;
24
+ scope?: string;
25
+ error?: string;
26
+ }
2
27
  /**
3
28
  * @see https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps
4
29
  */
@@ -63,4 +88,8 @@ export interface OAuthAtlassianConfig {
63
88
  /**
64
89
  * Atlassian User identity, Confluence, BRIE, Jira platform, Atlassian Personal data reporting
65
90
  */
66
- export declare function defineOAuthAtlassianEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthAtlassianConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
91
+ export declare function defineOAuthAtlassianEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthAtlassianConfig, {
92
+ user: AtlassianUser;
93
+ tokens: AtlassianTokens;
94
+ }>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
95
+ export {};
@@ -40,7 +40,7 @@ export interface OAuthFacebookConfig {
40
40
  */
41
41
  authorizationParams?: Record<string, string>;
42
42
  /**
43
- * Redirect URL to to allow overriding for situations like prod failing to determine public hostname
43
+ * Redirect URL to allow overriding for situations like prod failing to determine public hostname
44
44
  * @default process.env.NUXT_OAUTH_FACEBOOK_REDIRECT_URL or current URL
45
45
  */
46
46
  redirectURL?: string;
@@ -35,7 +35,9 @@ export function defineOAuthFacebookEventHandler({
35
35
  withQuery(config.authorizationURL, {
36
36
  client_id: config.clientId,
37
37
  redirect_uri: redirectURL,
38
- scope: config.scope.join(" ")
38
+ scope: config.scope.join(" "),
39
+ state: query.state || "",
40
+ ...config.authorizationParams
39
41
  })
40
42
  );
41
43
  }
@@ -50,4 +50,48 @@ export interface OAuthGitHubConfig {
50
50
  */
51
51
  redirectURL?: string;
52
52
  }
53
- export declare function defineOAuthGitHubEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthGitHubConfig>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
53
+ interface GitHubUser {
54
+ login: string;
55
+ id: number;
56
+ node_id: string;
57
+ avatar_url: string;
58
+ gravatar_id: string;
59
+ url: string;
60
+ html_url: string;
61
+ followers_url: string;
62
+ following_url: string;
63
+ gists_url: string;
64
+ starred_url: string;
65
+ subscriptions_url: string;
66
+ organizations_url: string;
67
+ repos_url: string;
68
+ events_url: string;
69
+ received_events_url: string;
70
+ type: string;
71
+ site_admin: boolean;
72
+ name: string;
73
+ company: string;
74
+ blog: string;
75
+ location: string;
76
+ email: string | null;
77
+ hireable: boolean | null;
78
+ bio: string | null;
79
+ twitter_username: string | null;
80
+ public_repos: number;
81
+ public_gists: number;
82
+ followers: number;
83
+ following: number;
84
+ created_at: string;
85
+ updated_at: string;
86
+ email_verified?: boolean;
87
+ }
88
+ interface GitHubTokens {
89
+ access_token: string;
90
+ scope: string;
91
+ token_type: string;
92
+ }
93
+ export declare function defineOAuthGitHubEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthGitHubConfig, {
94
+ user: GitHubUser;
95
+ tokens: GitHubTokens;
96
+ }>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
97
+ export {};
@@ -17,10 +17,13 @@ export function defineOAuthLineEventHandler({
17
17
  });
18
18
  const query = getQuery(event);
19
19
  if (query.error) {
20
- return onError(
21
- event,
22
- new Error(`Line login failed: ${query.error || "Unknown error"}`)
23
- );
20
+ const error = createError({
21
+ statusCode: 401,
22
+ message: `Line login failed: ${query.error || "Unknown error"}`,
23
+ data: query
24
+ });
25
+ if (!onError) throw error;
26
+ return onError(event, error);
24
27
  }
25
28
  if (!config.clientId || !config.clientSecret) {
26
29
  return handleMissingConfiguration(event, "line", ["clientId", "clientSecret"], onError);
@@ -25,6 +25,7 @@ export function defineOAuthMicrosoftEventHandler({ config, onSuccess, onError })
25
25
  response_type: "code",
26
26
  redirect_uri: redirectURL,
27
27
  scope: config.scope.join(" "),
28
+ state: query.state || "",
28
29
  ...config.authorizationParams
29
30
  })
30
31
  );
@@ -92,4 +92,7 @@ export interface OAuthSeznamUser {
92
92
  */
93
93
  gender?: string | null;
94
94
  }
95
- export declare function defineOAuthSeznamEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthSeznamConfig, OAuthSeznamUser>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
95
+ export declare function defineOAuthSeznamEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthSeznamConfig, {
96
+ user: OAuthSeznamUser;
97
+ tokens: unknown;
98
+ }>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
@@ -63,7 +63,7 @@ export function defineOAuthSteamEventHandler({ config, onSuccess, onError }) {
63
63
  }
64
64
  const idRegex = /^https?:\/\/steamcommunity\.com\/openid\/id\/(\d+)$/;
65
65
  const steamIdCheck = idRegex.exec(query["openid.claimed_id"]);
66
- const steamId = steamIdCheck[1];
66
+ const steamId = steamIdCheck?.[1];
67
67
  const user = await $fetch(withQuery("https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/", {
68
68
  key: config.apiKey,
69
69
  steamids: steamId
@@ -113,4 +113,7 @@ export interface OAuthStravaTokens {
113
113
  athlete: OAuthStravaUser;
114
114
  error?: string;
115
115
  }
116
- export declare function defineOAuthStravaEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthStravaConfig, OAuthStravaUser>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
116
+ export declare function defineOAuthStravaEventHandler({ config, onSuccess, onError, }: OAuthConfig<OAuthStravaConfig, {
117
+ user: OAuthStravaUser;
118
+ tokens: OAuthStravaTokens;
119
+ }>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
@@ -60,4 +60,7 @@ export interface OAuthWorkOSTokens {
60
60
  access_token: string;
61
61
  refresh_token: string;
62
62
  }
63
- export declare function defineOAuthWorkOSEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthWorkOSConfig, OAuthWorkOSUser, OAuthWorkOSTokens>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
63
+ export declare function defineOAuthWorkOSEventHandler({ config, onSuccess, onError }: OAuthConfig<OAuthWorkOSConfig, {
64
+ user: OAuthWorkOSUser;
65
+ tokens: OAuthWorkOSTokens;
66
+ }>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void>>;
@@ -1,6 +1,6 @@
1
1
  import type { H3Event } from 'h3';
2
+ import type { ValidateUserFunction } from '../../../types/webauthn.js';
2
3
  import type { WebAuthnUser, WebAuthnRegisterEventHandlerOptions } from '#auth-utils';
3
- import type { ValidateUserFunction } from '~/src/runtime/types/webauthn';
4
4
  export declare function defineWebAuthnRegisterEventHandler<T extends WebAuthnUser>({ storeChallenge, getChallenge, getOptions, validateUser, excludeCredentials, onSuccess, onError, }: WebAuthnRegisterEventHandlerOptions<T>): import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<void | import("@simplewebauthn/server").VerifiedRegistrationResponse | {
5
5
  creationOptions: import("@simplewebauthn/types").PublicKeyCredentialCreationOptionsJSON;
6
6
  attemptId: string;
@@ -1,6 +1,7 @@
1
+ import { getRequestURL } from "h3";
1
2
  import { getOAuthRedirectURL } from "../lib/utils.js";
2
3
  import { getClientMetadataFilename } from "../../utils/atproto.js";
3
- import { getRequestURL, useRuntimeConfig } from "#imports";
4
+ import { useRuntimeConfig } from "#imports";
4
5
  export function getAtprotoClientMetadata(event, provider, config) {
5
6
  const providerRuntimeConfig = useRuntimeConfig(event).oauth[provider];
6
7
  const scopes = [.../* @__PURE__ */ new Set(["atproto", ...config?.scope ?? [], ...providerRuntimeConfig.scope ?? []])];
@@ -20,24 +20,20 @@ export declare const sessionHooks: import("hookable").Hookable<SessionHooks, imp
20
20
  * @param event The Request (h3) event
21
21
  * @returns The user session
22
22
  */
23
- export declare function getUserSession(event: UseSessionEvent): Promise<{
24
- id: any;
25
- user?: import("#auth-utils").User;
26
- secure?: import("#auth-utils").SecureSessionData;
27
- }>;
23
+ export declare function getUserSession(event: UseSessionEvent): Promise<UserSession>;
28
24
  /**
29
25
  * Set a user session
30
26
  * @param event The Request (h3) event
31
27
  * @param data User session data, please only store public information since it can be decoded with API calls
32
28
  * @see https://github.com/atinux/nuxt-auth-utils
33
29
  */
34
- export declare function setUserSession(event: H3Event, data: UserSession, config?: Partial<SessionConfig>): Promise<UserSession>;
30
+ export declare function setUserSession(event: H3Event, data: Omit<UserSession, 'id'>, config?: Partial<SessionConfig>): Promise<UserSession>;
35
31
  /**
36
32
  * Replace a user session
37
33
  * @param event The Request (h3) event
38
34
  * @param data User session data, please only store public information since it can be decoded with API calls
39
35
  */
40
- export declare function replaceUserSession(event: H3Event, data: UserSession, config?: Partial<SessionConfig>): Promise<UserSession>;
36
+ export declare function replaceUserSession(event: H3Event, data: Omit<UserSession, 'id'>, config?: Partial<SessionConfig>): Promise<UserSession>;
41
37
  /**
42
38
  * Clear the user session and removing the session cookie
43
39
  * @param event The Request (h3) event
@@ -6,8 +6,8 @@ export const sessionHooks = createHooks();
6
6
  export async function getUserSession(event) {
7
7
  const session = await _useSession(event);
8
8
  return {
9
- id: session.id,
10
- ...session.data
9
+ ...session.data,
10
+ id: session.id
11
11
  };
12
12
  }
13
13
  export async function setUserSession(event, data, config) {
@@ -2,11 +2,11 @@ import type { H3Event, H3Error } from 'h3';
2
2
  export type ATProtoProvider = 'bluesky';
3
3
  export type OAuthProvider = ATProtoProvider | 'atlassian' | 'auth0' | 'authentik' | 'azureb2c' | 'battledotnet' | 'cognito' | 'discord' | 'dropbox' | 'facebook' | 'gitea' | 'github' | 'gitlab' | 'google' | 'hubspot' | 'instagram' | 'kick' | 'keycloak' | 'line' | 'linear' | 'linkedin' | 'microsoft' | 'paypal' | 'polar' | 'spotify' | 'seznam' | 'steam' | 'strava' | 'tiktok' | 'twitch' | 'vk' | 'workos' | 'x' | 'xsuaa' | 'yandex' | 'zitadel' | 'apple' | 'livechat' | 'salesforce' | 'slack' | 'heroku' | (string & {});
4
4
  export type OnError = (event: H3Event, error: H3Error) => Promise<void> | void;
5
- export interface OAuthConfig<TConfig, TUser = any, TTokens = any> {
5
+ export interface OAuthConfig<TConfig, TResult = {
6
+ user: any;
7
+ tokens: any;
8
+ }> {
6
9
  config?: TConfig;
7
- onSuccess: (event: H3Event, result: {
8
- user: TUser;
9
- tokens: TTokens;
10
- }) => Promise<void> | void;
10
+ onSuccess: (event: H3Event, result: TResult) => Promise<void> | void;
11
11
  onError?: OnError;
12
12
  }
@@ -7,7 +7,7 @@ export interface UserSession {
7
7
  /**
8
8
  * Session ID
9
9
  */
10
- id?: string;
10
+ id: string;
11
11
  /**
12
12
  * User session data, available on client and server
13
13
  */
@@ -22,7 +22,6 @@ export interface UserSession {
22
22
  [key: string]: unknown;
23
23
  }
24
24
  export interface UserSessionRequired extends UserSession {
25
- id: string;
26
25
  user: User;
27
26
  }
28
27
  export interface UserSessionComposable {
@@ -41,7 +40,7 @@ export interface UserSessionComposable {
41
40
  /**
42
41
  * The session object.
43
42
  */
44
- session: Ref<UserSession>;
43
+ session: Ref<UserSession | null>;
45
44
  /**
46
45
  * Fetch the user session from the server.
47
46
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-auth-utils",
3
- "version": "0.5.18",
3
+ "version": "0.5.20",
4
4
  "description": "Add Authentication to Nuxt applications with secured & sealed cookies sessions.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,7 +31,7 @@
31
31
  "lint:fix": "eslint . --fix",
32
32
  "test": "vitest run",
33
33
  "test:types": "vue-tsc --noEmit",
34
- "test:types:playground": "cd playground && vue-tsc --noEmit",
34
+ "test:types:playground": "nuxt typecheck playground",
35
35
  "test:watch": "vitest watch"
36
36
  },
37
37
  "dependencies": {