@hichchi/ngx-auth 0.0.4 → 0.0.5
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 +120 -150
- package/fesm2022/hichchi-ngx-auth.mjs +16 -47
- package/fesm2022/hichchi-ngx-auth.mjs.map +1 -1
- package/package.json +5 -5
- package/types/hichchi-ngx-auth.d.ts +15 -46
|
@@ -5,7 +5,7 @@ import { FormBuilder, Validators, FormsModule, ReactiveFormsModule } from '@angu
|
|
|
5
5
|
import { AuthEndpoint, isRoleObject, AuthField, AuthErrorResponseCode } from '@hichchi/nest-connector/auth';
|
|
6
6
|
import { take, map, tap, catchError, EMPTY, firstValueFrom, ReplaySubject, throwError, switchMap, filter } from 'rxjs';
|
|
7
7
|
import { Endpoint, HttpClientErrorStatus } from '@hichchi/nest-connector';
|
|
8
|
-
import { CrudHttpService, skipNotifyContext, validatedFormData
|
|
8
|
+
import { CrudHttpService, extractSubdomain, skipNotifyContext, validatedFormData } from '@hichchi/ngx-utils';
|
|
9
9
|
import { toFirstCase } from '@hichchi/utils';
|
|
10
10
|
import { signalStore, withState, withComputed, withMethods, patchState } from '@ngrx/signals';
|
|
11
11
|
import { withStorageSync } from '@angular-architects/ngrx-toolkit';
|
|
@@ -303,7 +303,8 @@ class AuthService extends CrudHttpService {
|
|
|
303
303
|
const left = (window.screen.width - GOOGLE_AUTH_POPUP_WIDTH) / 2;
|
|
304
304
|
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
305
305
|
const top = (window.screen.height - GOOGLE_AUTH_POPUP_HEIGHT) / 2;
|
|
306
|
-
const
|
|
306
|
+
const tenant = extractSubdomain(this.config.splitDomain) || this.config.tenant;
|
|
307
|
+
const popup = window.open(`${this.config.apiBaseURL}/${Endpoint.AUTH}/${AuthEndpoint.GOOGLE_SIGN_IN}?redirectUrl=${window.location.origin}&tenant=${tenant}`, "google-login-popup",
|
|
307
308
|
// eslint-disable-next-line prefer-template
|
|
308
309
|
"resizable=no, location=no, toolbar=false, width=" +
|
|
309
310
|
GOOGLE_AUTH_POPUP_WIDTH +
|
|
@@ -2202,12 +2203,10 @@ function authInterceptor(redirect, onRedirect) {
|
|
|
2202
2203
|
* The module must be configured using the forRoot() method to provide the necessary
|
|
2203
2204
|
* authentication configuration.
|
|
2204
2205
|
*
|
|
2205
|
-
*
|
|
2206
|
-
* - `
|
|
2207
|
-
*
|
|
2208
|
-
*
|
|
2209
|
-
* - `true`: resolves subdomain dynamically from the current host context
|
|
2210
|
-
* - `false` / `undefined`: keeps `apiBaseURL` unchanged
|
|
2206
|
+
* Tenant handling:
|
|
2207
|
+
* - `tenant` can be provided in the configuration or dynamically set in requests
|
|
2208
|
+
* via a custom HTTP header (`x-tenant`, controlled by `TENANT_HEADER_KEY`).
|
|
2209
|
+
* - This approach replaces previous subdomain-based tenant resolution.
|
|
2211
2210
|
*
|
|
2212
2211
|
* @example
|
|
2213
2212
|
* ```typescript
|
|
@@ -2238,26 +2237,12 @@ function authInterceptor(redirect, onRedirect) {
|
|
|
2238
2237
|
*
|
|
2239
2238
|
* @example
|
|
2240
2239
|
* ```typescript
|
|
2241
|
-
* //
|
|
2240
|
+
* // Optional static tenant header
|
|
2242
2241
|
* @NgModule({
|
|
2243
2242
|
* imports: [
|
|
2244
2243
|
* NgxHichchiAuthModule.forRoot({
|
|
2245
2244
|
* apiBaseURL: 'https://api.example.com',
|
|
2246
|
-
*
|
|
2247
|
-
* })
|
|
2248
|
-
* ]
|
|
2249
|
-
* })
|
|
2250
|
-
* export class AppModule { }
|
|
2251
|
-
* ```
|
|
2252
|
-
*
|
|
2253
|
-
* @example
|
|
2254
|
-
* ```typescript
|
|
2255
|
-
* // Configuration with dynamic subdomain resolution
|
|
2256
|
-
* @NgModule({
|
|
2257
|
-
* imports: [
|
|
2258
|
-
* NgxHichchiAuthModule.forRoot({
|
|
2259
|
-
* apiBaseURL: 'https://api.example.com',
|
|
2260
|
-
* prependSubdomain: true
|
|
2245
|
+
* tenant: 'tenant-a'
|
|
2261
2246
|
* })
|
|
2262
2247
|
* ]
|
|
2263
2248
|
* })
|
|
@@ -2277,17 +2262,11 @@ class NgxHichchiAuthModule {
|
|
|
2277
2262
|
* Configures the NgxHichchiAuthModule with the provided authentication configuration
|
|
2278
2263
|
*
|
|
2279
2264
|
* This static method sets up the module with the necessary providers and configuration
|
|
2280
|
-
* for authentication functionality.
|
|
2281
|
-
*
|
|
2282
|
-
*
|
|
2283
|
-
* for the module to function properly.
|
|
2284
|
-
*
|
|
2285
|
-
* `prependSubdomain` behavior:
|
|
2286
|
-
* - `string`: prepend that subdomain to the API host
|
|
2287
|
-
* - `true`: derive subdomain dynamically from the current host context
|
|
2288
|
-
* - `false` / `undefined`: do not prepend a subdomain
|
|
2265
|
+
* for authentication functionality. The configuration includes the `apiBaseURL` for
|
|
2266
|
+
* all authentication requests, and optionally a `tenant` string that is attached
|
|
2267
|
+
* to requests via the `TENANT_HEADER_KEY` header.
|
|
2289
2268
|
*
|
|
2290
|
-
* @param config - The authentication configuration object containing API endpoints and settings
|
|
2269
|
+
* @param config - The authentication configuration object containing API endpoints, tenant, and other settings
|
|
2291
2270
|
* @returns A ModuleWithProviders object configured with authentication providers
|
|
2292
2271
|
*
|
|
2293
2272
|
* @example
|
|
@@ -2309,29 +2288,19 @@ class NgxHichchiAuthModule {
|
|
|
2309
2288
|
*
|
|
2310
2289
|
* @example
|
|
2311
2290
|
* ```typescript
|
|
2312
|
-
* //
|
|
2313
|
-
* NgxHichchiAuthModule.forRoot({
|
|
2314
|
-
* apiBaseURL: 'https://api.example.com',
|
|
2315
|
-
* prependSubdomain: 'tenant-a'
|
|
2316
|
-
* })
|
|
2317
|
-
* ```
|
|
2318
|
-
*
|
|
2319
|
-
* @example
|
|
2320
|
-
* ```typescript
|
|
2321
|
-
* // Dynamic subdomain
|
|
2291
|
+
* // Configuration with static tenant
|
|
2322
2292
|
* NgxHichchiAuthModule.forRoot({
|
|
2323
2293
|
* apiBaseURL: 'https://api.example.com',
|
|
2324
|
-
*
|
|
2294
|
+
* tenant: 'tenant-a'
|
|
2325
2295
|
* })
|
|
2326
2296
|
* ```
|
|
2327
2297
|
*
|
|
2328
2298
|
* @see {@link AuthConfig} Interface defining the configuration structure
|
|
2329
2299
|
* @see {@link AUTH_CONFIG} Injection token for the authentication configuration
|
|
2330
2300
|
* @see {@link AuthService} Service that uses the provided configuration
|
|
2331
|
-
* @see {@link
|
|
2301
|
+
* @see {@link TENANT_HEADER_KEY} Constant used to attach tenant header to requests
|
|
2332
2302
|
*/
|
|
2333
2303
|
static forRoot(config) {
|
|
2334
|
-
config.apiBaseURL = prependSubdomainToUrlBrowser(config.apiBaseURL, config.splitDomain, config.devSubdomain);
|
|
2335
2304
|
return {
|
|
2336
2305
|
ngModule: NgxHichchiAuthModule,
|
|
2337
2306
|
providers: [{ provide: AUTH_CONFIG, useValue: config }, AuthService],
|