Skip to content

Commit 44a5f45

Browse files
committed
fix(web): reverting to previous webauth redirect logic
1 parent 8835175 commit 44a5f45

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

templates/web/src/client.ts.twig

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,10 @@ class Client {
497497

498498
/**
499499
* Subscribes to {{spec.title | caseUcfirst}} events and passes you the payload in realtime.
500-
*
501-
* @param {string|string[]} channels
500+
*
501+
* @param {string|string[]} channels
502502
* Channel to subscribe - pass a single channel as a string or multiple with an array of strings.
503-
*
503+
*
504504
* Possible channels are:
505505
* - account
506506
* - collections
@@ -633,21 +633,6 @@ class Client {
633633
return response;
634634
}
635635

636-
async redirect(method: string, url: URL, headers: Headers = {}, params: Payload = {}): Promise<string> {
637-
const { uri, options } = this.prepareRequest(method, url, headers, params);
638-
639-
const response = await fetch(uri, {
640-
...options,
641-
redirect: 'manual'
642-
});
643-
644-
if (response.status !== 301 && response.status !== 302) {
645-
throw new {{spec.title | caseUcfirst}}Exception('Invalid redirect', response.status);
646-
}
647-
648-
return response.headers.get('location') || '';
649-
}
650-
651636
async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}, responseType = 'json'): Promise<any> {
652637
const { uri, options } = this.prepareRequest(method, url, headers, params);
653638

templates/web/src/services/template.ts.twig

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Service } from '../service';
12
import { {{ spec.title | caseUcfirst}}Exception, Client, type Payload, UploadProgress } from '../client';
23
import type { Models } from '../models';
34
{% set added = [] %}
@@ -69,17 +70,25 @@ export class {{ service.name | caseUcfirst }} {
6970
{%~ endfor %}
7071
}
7172

73+
{%~ if method.type == 'location' or method.type == 'webAuth' %}
74+
{%~ if method.auth|length > 0 %}
75+
{%~ for node in method.auth %}
76+
{%~ for key,header in node|keys %}
77+
payload['{{header|caseLower}}'] = this.client.config.{{header|caseLower}};
78+
{%~ endfor %}
79+
{%~ endfor %}
80+
{%~ endif %}
81+
for (const [key, value] of Object.entries(Service.flatten(payload))) {
82+
uri.searchParams.append(key, value);
83+
}
84+
{%~ endif %}
85+
7286
{%~ if method.type == 'webAuth' %}
73-
const location = await this.client.redirect(
74-
'{{ method.method | caseLower }}',
75-
uri,
76-
apiHeaders,
77-
payload
78-
);
79-
if (typeof window !== 'undefined') {
80-
window.location.href = location;
87+
if (typeof window !== 'undefined' && window?.location) {
88+
window.location.href = uri.toString();
89+
} else {
90+
return uri.toString();
8191
}
82-
return location.toString();
8392
{%~ elseif method.type == 'location' %}
8493
{%~ for node in method.auth %}
8594
{%~ for key, header in node|keys %}

0 commit comments

Comments
 (0)