Skip to content

Commit 4644bd1

Browse files
authored
update: storage watcher & oauth2 (#88)
1 parent 946768b commit 4644bd1

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nuxt-alt/auth",
3-
"version": "3.0.3",
3+
"version": "3.0.4",
44
"description": "An alternative module to @nuxtjs/auth",
55
"homepage": "https://github.com/nuxt-alt/auth",
66
"author": "Denoder",

src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ModuleOptions } from './types';
2-
import { addImports, addPlugin, addPluginTemplate, addTemplate, createResolver, defineNuxtModule, installModule, addRouteMiddleware } from '@nuxt/kit';
2+
import { addImports, addPluginTemplate, addTemplate, createResolver, defineNuxtModule, installModule, addRouteMiddleware } from '@nuxt/kit';
33
import { name, version } from '../package.json';
44
import { resolveStrategies } from './resolve';
55
import { moduleDefaults } from './options';

src/runtime/core/storage.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ModuleOptions, AuthStore, AuthState, StoreMethod, StoreIncludeOptions } from '../../types';
22
import type { NuxtApp } from '#app';
3+
import type { Pinia, StoreDefinition } from 'pinia';
34
import { isUnset, isSet, decodeValue, encodeValue, setH3Cookie } from '../../utils';
4-
import { defineStore, type Pinia, type StoreDefinition } from 'pinia';
55
import { parse, serialize, type CookieSerializeOptions } from 'cookie-es';
66
import { useState } from '#imports';
77
import { watch, type Ref } from 'vue';
@@ -101,12 +101,13 @@ export class Storage {
101101
// Local state (reactive)
102102
// ------------------------------------
103103

104-
#initState() {
104+
async #initState() {
105105
// Use pinia for local state's if possible
106106
const pinia = this.ctx.$pinia as Pinia
107107
this.#piniaEnabled = this.options.stores.pinia!.enabled && !!pinia;
108108

109109
if (this.#piniaEnabled) {
110+
const { defineStore } = await import('pinia')
110111
this.#PiniaStore = defineStore(this.options.stores.pinia?.namespace!, {
111112
state: (): AuthState => ({ ...this.options.initialState })
112113
});
@@ -154,11 +155,11 @@ export class Storage {
154155

155156
watchState(watchKey: string, fn: (value: any) => void) {
156157
if (this.#piniaEnabled) {
157-
watch(() => this.#initPiniaStore[watchKey as keyof AuthStore], (modified, old) => {
158+
watch(() => this.#initPiniaStore?.[watchKey as keyof AuthStore], (modified, old) => {
158159
fn(modified)
159160
}, { deep: true })
160161
} else {
161-
watch(() => this.#initStore.value[watchKey], (modified, old) => {
162+
watch(() => this.#initStore?.value?.[watchKey], (modified, old) => {
162163
fn(modified)
163164
}, { deep: true })
164165
}

src/runtime/providers/google.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ export function google(nuxt: Nuxt, strategy: ProviderPartialOptions<GoogleProvid
1010
scheme: 'oauth2',
1111
endpoints: {
1212
authorization: 'https://accounts.google.com/o/oauth2/v2/auth',
13-
userInfo: 'https://www.googleapis.com/oauth2/v3/userinfo',
14-
token: 'https://oauth2.googleapis.com/token'
13+
userInfo: 'https://www.googleapis.com/oauth2/v3/userinfo'
1514
},
1615
scope: ['openid', 'profile', 'email'],
1716
};

src/runtime/schemes/oauth2.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface Oauth2SchemeOptions extends SchemeOptions, TokenableSchemeOptio
2929
clientSecretTransport: 'body' | 'aurthorization_header';
3030
scope: string | string[];
3131
state: string;
32-
codeChallengeMethod: 'implicit' | 'S256' | 'plain' | '';
32+
codeChallengeMethod: 'implicit' | 'S256' | 'plain' | '' | false;
3333
acrValues: string;
3434
audience: string;
3535
autoLogout: boolean;
@@ -77,7 +77,7 @@ const DEFAULTS: SchemePartialOptions<Oauth2SchemeOptions> = {
7777
property: false,
7878
},
7979
responseType: 'token',
80-
codeChallengeMethod: 'implicit',
80+
codeChallengeMethod: false,
8181
clientWindow: false,
8282
clientWindowWidth: 400,
8383
clientWindowHeight: 600
@@ -216,6 +216,10 @@ export class Oauth2Scheme<OptionsT extends Oauth2SchemeOptions = Oauth2SchemeOpt
216216
...options.params,
217217
};
218218

219+
if (!opts.code_challenge_method) {
220+
delete opts.code_challenge_method;
221+
}
222+
219223
if (this.options.organization) {
220224
opts.organization = this.options.organization;
221225
}

0 commit comments

Comments
 (0)