Skip to content

Commit 009c5ff

Browse files
authored
Merge pull request #28 from containerish/adhoc-changes
Add: Forgot password API fix
2 parents c245fe1 + 757ae48 commit 009c5ff

File tree

8 files changed

+83
-33
lines changed

8 files changed

+83
-33
lines changed

src/apis/auth.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class Auth extends HttpClient {
116116
}
117117

118118
public ForgotPasswordCallback = async (newPassword: string, token: string) => {
119-
const path= `/reset-password?kind=forgot_password_callback`
119+
const path= `/reset-forgotten-password`
120120

121121
const body = {
122122
"new_password": newPassword,
@@ -125,6 +125,7 @@ export class Auth extends HttpClient {
125125
const resp = this.http.post(path, body, {headers: {
126126
'Authorization': 'Bearer ' + token,
127127
}})
128+
128129
return resp;
129130
}
130131

@@ -183,6 +184,17 @@ export class Auth extends HttpClient {
183184
goto(import.meta.env.VITE_OPEN_REGISTRY_BACKEND_URL + "/auth/github/login")
184185
}
185186

187+
public publicPaths = new Map([
188+
['/', 'root'],
189+
['/about', 'about'],
190+
['/faq', 'faq'],
191+
['/search', 'search'],
192+
['/auth/verify', 'authVerify'],
193+
['/auth/unhandled', 'unhandled'],
194+
['/auth/forgot-password', 'forgot-password']
195+
]);
196+
197+
186198
private getGithubOAuthUrl = () => {
187199
return `https://github.com/login/oauth/authorize/?client_id=${import.meta.env.VITE_GITHUB_CLIENT_ID}&redirect_uri=${import.meta.env.VITE_OPEN_REGISTRY_BACKEND_URL}/auth/github/callback&scope=user:email&state=skljdfkljsdjfklj`;
188200
}

src/apis/httpClient.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ abstract class HttpClient {
1313
baseURL,
1414
headers,
1515
withCredentials: true,
16-
httpAgent: this.getUserAgent(),
17-
httpsAgent: this.getUserAgent(),
1816
});
1917

2018
this._responseInterceptor();
@@ -28,6 +26,8 @@ abstract class HttpClient {
2826
req.withCredentials = false;
2927
} else {
3028
req.withCredentials = true;
29+
// @TODO (jay-dee7) we need to set this header
30+
// req.headers['User-Agent'] = this.getUserAgent();
3131
}
3232

3333
return req;
@@ -54,7 +54,8 @@ abstract class HttpClient {
5454
}
5555

5656
private getUserAgent = () => {
57-
return import.meta.env.VITE_OPEN_REGISTRY_APP_NAME + "/" + import.meta.env.VITE_OPEN_REGISTRY_ENVIRONMENT
57+
const agentName = `${import.meta.env.VITE_OPEN_REGISTRY_APP_NAME}/${import.meta.env.VITE_OPEN_REGISTRY_ENVIRONMENT} ${import.meta.env.VITE_OPEN_REGISTRY_APP_VERSION}`
58+
return agentName;
5859
}
5960
}
6061

src/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ interface ImportMetaEnv {
88
VITE_OPEN_REGISTRY_SUPPORT_API_KEY: string
99
VITE_OPEN_REGISTRY_SUPPORT_ENDPOINT: string
1010
VITE_OPEN_REGISTRY_SUPPORT_EMAILS: string
11+
VITE_OPEN_REGISTRY_APP_VERSION: string
1112
}

src/lib/navbar.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
<div class="container px-6 mx-auto half:px-1 uw:px-12">
3232
<div class="flex flex-col md:justify-between md:items-center">
3333
<div class="flex items-center justify-between w-full">
34-
<div class="cursor-pointer flex items-center half:ml-5">
35-
<picture class="md:w-44" on:click={() => goto('/')}>
36-
<img class="h-full w-full" src="/logo.svg" alt="opener" />
34+
<div on:click={() => goto('/')} class="cursor-pointer flex items-center half:ml-5">
35+
<picture class="md:w-44">
36+
<img class="h-full w-full" src="/logo.svg" alt="openeregistry" />
3737
</picture>
3838
</div>
3939
<NavbarDefault {pathname} {openSignInModal} />

src/routes/__error.svelte

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<script context="module">
1+
<script context="module" lang="ts">
22
export function load({ error, status }) {
33
return {
44
props: {
@@ -8,10 +8,15 @@
88
}
99
</script>
1010

11-
<script>
12-
export let title;
11+
<script lang="ts">
12+
export let title: string;
1313
</script>
1414

15-
<div class="bg-brown-200 flex-col w-full h-full flex justify-center items-center">
15+
<div
16+
class="bg-brown-200 text-center min-h-[70vh] py-8 2xl:py-16 flex-col w-full h-full flex justify-center items-center"
17+
>
1618
<img class="w-4/6" src="/404-not-found.svg" alt="" />
19+
<div class="w-full h-full">
20+
<span class="text-brown-900 text-xl">{title}</span>
21+
</div>
1722
</div>

src/routes/__layout.svelte

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,75 @@
11
<script context="module" lang="ts">
2+
import { Auth, type User } from '../apis/auth';
3+
const auth = new Auth();
4+
25
export const load = async ({ url }) => {
36
const signinPath = url.pathname === '/search' ? url.pathname : undefined;
47
const u = new URLSearchParams(url.search);
5-
const signin = u.get('signin');
8+
const openSignInModal = u.get('signin');
9+
const pathname = url.pathname;
10+
11+
if (auth.publicPaths.has(pathname)) {
12+
return {
13+
props: {
14+
signinPath: signinPath,
15+
pathname: url.pathname,
16+
openSignInModal: openSignInModal,
17+
authenticated: false
18+
}
19+
};
20+
}
621
7-
return {
8-
props: {
9-
signinPath: signinPath,
10-
pathname: url.pathname,
11-
openSignInModal: signin
22+
let s: number;
23+
try {
24+
const { data, status } = await auth.GetUserWithSession();
25+
s = status;
26+
return {
27+
props: {
28+
signinPath: signinPath,
29+
pathname: url.pathname,
30+
openSignInModal: openSignInModal,
31+
user: data,
32+
authenticated: true
33+
}
34+
};
35+
} catch (err) {
36+
if (err) {
37+
return {
38+
status: s,
39+
error: err,
40+
props: {
41+
signinPath: signinPath,
42+
pathname: url.pathname,
43+
openSignInModal: openSignInModal,
44+
authenticated: false
45+
}
46+
};
1247
}
13-
};
48+
}
1449
};
1550
</script>
1651

1752
<script lang="ts">
1853
import '../app.css';
1954
import { onMount } from 'svelte';
20-
import { session } from '$app/stores';
2155
import Footer from '$lib/footer.svelte';
2256
import Navbar from '$lib/navbar.svelte';
23-
import { Auth } from '../apis/auth';
24-
export let pathname: string;
57+
import { session } from '$app/stores';
2558
export let signinPath: string;
2659
export let openSignInModal: boolean;
60+
export let user: User;
2761
28-
const auth = new Auth();
2962
onMount(async () => {
30-
if (!pathname || pathname === '/' || pathname === '/about' || pathname === '/faq') {
31-
return;
32-
}
33-
34-
const { data, status } = await auth.GetUserWithSession();
35-
if (status === 200) {
63+
if (user) {
3664
// @ts-ignore
37-
$session.user = data;
65+
$session.user = user;
3866
// @ts-ignore
3967
$session.authenticated = true;
4068
return;
4169
}
70+
71+
// @ts-ignore
72+
$session.authenticated = false;
4273
});
4374
</script>
4475

src/routes/auth/[slug].svelte

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@
8282
return;
8383
}
8484
85-
timer = setTimeout(async () => {
86-
await goto('/repositories');
87-
}, 1000);
85+
goto('/repositories');
8886
break;
8987
case forgotPassword:
9088
showModal = true;

src/routes/repositories/index.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
// @ts-ignore
5353
if (!$session.authenticated) {
5454
await goto('/auth/unauthorized');
55+
return;
5556
}
5657
5758
// @ts-ignore
@@ -119,8 +120,9 @@
119120
y="0px"
120121
viewBox="0 0 255 255"
121122
xml:space="preserve"
122-
><polygon class="fill-current" points="0,0 127.5,127.5 255,0" /></svg
123123
>
124+
<polygon class="fill-current" points="0,0 127.5,127.5 255,0" />
125+
</svg>
124126
</span>
125127
<div id="arrow" data-popper-arrow />
126128
</div>

0 commit comments

Comments
 (0)