Skip to content

Commit 258af21

Browse files
author
Florin Mateescu
committed
- authentication is now handled securely through cookies
- removed unnecessary localstorage for auth
1 parent b928705 commit 258af21

File tree

13 files changed

+55
-315
lines changed

13 files changed

+55
-315
lines changed

apps/express/src/auth/index.ts

-9
This file was deleted.

apps/express/src/auth/register.ts

-75
This file was deleted.

apps/express/src/main.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import payload from 'payload';
77
import cors from 'cors';
88
import { createTransport } from 'nodemailer';
99
import bodyParser from 'body-parser';
10-
import { register, registerPath, verifyAccount, verifyPath } from './auth';
1110
import { useInfrastructure } from './utils/use-infrastructure';
1211
import dotenv from 'dotenv';
1312
import path from 'path';
@@ -68,8 +67,7 @@ const start = async () => {
6867
/**
6968
* Extra custom routes
7069
*/
71-
app.post(registerPath, register);
72-
app.post(verifyPath, verifyAccount);
70+
7371
/**
7472
* End extra custom routes
7573
*/

apps/express/src/payloadcms/collections/UsersCollection.ts

+1-41
Original file line numberDiff line numberDiff line change
@@ -88,38 +88,23 @@ const collection: CollectionConfig = {
8888
update: accessAdminOrMeOnly,
8989
delete: () => false,
9090
unlock: accessAdminOnly,
91-
create: accessAdminOnly,
91+
create: () => true,
9292
},
9393
fields: [
9494
{
9595
name: 'email',
9696
type: 'email',
9797
required: true,
98-
access: {
99-
read: () => true,
100-
update: () => false,
101-
create: fieldAccessAdminOnly,
102-
},
10398
},
10499
{
105100
name: 'firstName',
106101
type: 'text',
107102
required: true,
108-
access: {
109-
read: () => true,
110-
update: fieldAccessMeOnly,
111-
create: fieldAccessAdminOrMeOnly,
112-
},
113103
},
114104
{
115105
name: 'lastName',
116106
type: 'text',
117107
required: true,
118-
access: {
119-
read: () => true,
120-
update: fieldAccessMeOnly,
121-
create: fieldAccessAdminOrMeOnly,
122-
},
123108
},
124109
{
125110
name: 'username',
@@ -131,31 +116,6 @@ const collection: CollectionConfig = {
131116
create: () => true,
132117
},
133118
},
134-
{
135-
name: 'verified',
136-
type: 'checkbox',
137-
defaultValue: false,
138-
required: true,
139-
admin: {
140-
hidden: true,
141-
},
142-
access: {
143-
read: () => true,
144-
update: () => false,
145-
create: () => false,
146-
},
147-
},
148-
{
149-
name: '_verified',
150-
type: 'checkbox',
151-
defaultValue: false,
152-
required: true,
153-
access: {
154-
read: () => true,
155-
update: () => false,
156-
create: () => false,
157-
},
158-
},
159119
{
160120
name: 'roles',
161121
saveToJWT: true,

apps/express/tsconfig.app.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"types": ["node"]
77
},
88
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
9-
"include": ["src/**/*.ts"]
9+
"include": ["src/**/*.ts", "src/**/*.tsx"]
1010
}

libs/angular/src/spa/config/interceptors/authorization.interceptor.ts

-108
This file was deleted.

libs/angular/src/spa/config/interceptors/http.interceptor.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { PLATFORM_ID, inject } from '@angular/core';
1313

1414
export const httpErrorHandlingInterceptor: HttpInterceptorFn = (
1515
request: HttpRequest<unknown>,
16-
next: HttpHandlerFn,
16+
next: HttpHandlerFn
1717
) => {
1818
const platformId = inject(PLATFORM_ID);
1919
const isBrowser: boolean = isPlatformBrowser(platformId);
@@ -25,11 +25,6 @@ export const httpErrorHandlingInterceptor: HttpInterceptorFn = (
2525
.pipe(
2626
catchError((response: HttpErrorResponse) => {
2727
let error = response.error;
28-
// handle very strange behavior when token is expiring while
29-
// redirecting from server dashboard to frontend domain
30-
if (response.status === 0) {
31-
return of();
32-
}
3328

3429
switch (response.status) {
3530
case 400: {
@@ -82,14 +77,14 @@ export const httpErrorHandlingInterceptor: HttpInterceptorFn = (
8277
: ['Something went wrong.'],
8378
},
8479
url: response.url === null ? undefined : response.url,
85-
}),
80+
})
8681
);
8782
}
8883
default: {
8984
return throwError(() => error);
9085
}
9186
}
92-
}),
87+
})
9388
)
9489
.pipe(
9590
map((data: any) => {
@@ -105,7 +100,7 @@ export const httpErrorHandlingInterceptor: HttpInterceptorFn = (
105100
} else {
106101
return data;
107102
}
108-
}),
103+
})
109104
);
110105
}
111106
};

libs/angular/src/spa/core/api/api-endpoints.service.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,5 @@ export class ApiEndpointsService {
1414
return join([this.base, path], '/');
1515
}
1616

17-
public routes = {
18-
auth: {
19-
register: this.join('auth/register'),
20-
verify: (token: string) => `${this.join('auth/verify')}/${token}`,
21-
},
22-
};
17+
public routes = {};
2318
}

libs/angular/src/spa/core/api/payload-api-endpoints.service.ts

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export class PayloadApiEndpointsService {
2828
logout: this.create(this.usersSlug, 'logout'),
2929
forgotPassword: this.create(this.usersSlug, 'forgot-password'),
3030
resetPassword: this.create(this.usersSlug, 'reset-password'),
31+
register: this.create(this.usersSlug),
32+
verify: (token: string) => this.create(this.usersSlug, `verify/${token}`),
3133
refresh: this.create(this.usersSlug, 'refresh-token'),
3234
},
3335
user: {

0 commit comments

Comments
 (0)