-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add admin authentication functionality + Lots of Authentication fixes #94
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
faa0d71
admin is added on database init
Eric-Fithian 2fa67a0
tests not working but vendor auth working and user is stored in context
Eric-Fithian fe6cd56
Merge branch 'main' into 92-admin-service-on-frontend
Eric-Fithian 6484711
login cookie auth and user set working, cookie testing also implemented
Eric-Fithian 772f169
fixed newUserFromCookie Method
Eric-Fithian 0298b8e
added httpClient as instance variable to services
Eric-Fithian 935d70c
Remove password from admin cookie. Frontend doesn't need to see the p…
nh602 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,19 @@ | ||
// import Permission from './Permission.js'; | ||
import Cookies from 'js-cookie'; | ||
import {jwtDecode} from 'jwt-decode'; | ||
|
||
/* | ||
Storage mechanism for the currently logged-in user. | ||
*/ | ||
export default class User { | ||
constructor(id, name, email, isadmin, phone_number=null, website=null) { | ||
constructor(id, name, email, isadmin, phoneNumber=null, website=null) { | ||
this.id = id; | ||
this.name = name; | ||
this.email = email; | ||
this.isadmin = isadmin; | ||
this.phone_number = phone_number; | ||
this.phoneNumber = phoneNumber; | ||
this.website = website; | ||
} | ||
|
||
// isAdmin() { | ||
// return this.permission === Permission.Admin; | ||
// } | ||
|
||
// isVendor() { | ||
// return this.permission === Permission.Vendor; | ||
// } | ||
|
||
static createFromCookie() { | ||
if (Cookies.get('auth_pim') != undefined) { | ||
const cookie = Cookies.get('auth_pim'); | ||
const decode = jwtDecode(cookie); | ||
|
||
return User(decode.admin_id, decode.name, decode.email, true, null, null); | ||
} else if ( Cookies.get('auth') != undefined ) { | ||
const cookie = Cookies.get('auth'); | ||
const decode = jwtDecode(cookie); | ||
|
||
return User(decode.vendor_id, decode.name, decode.email, false, decode.phone_number, decode.website); | ||
} else { | ||
return undefined; | ||
} | ||
static newUserFromCookie(cookie, isadmin) { | ||
const decode = jwtDecode(cookie); | ||
return new User(decode.admin_id, decode.name, decode.email, isadmin, null, null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export default class AdminsRepository { | ||
constructor(httpClient) { | ||
this.httpClient = httpClient; | ||
} | ||
async authenticateAdmin(adminData) { | ||
try { | ||
const response = await this.httpClient.axiosInstance.post('admins/login', adminData); | ||
// this.httpClient.processCookie(response.headers['set-cookie'][0]); | ||
return response; | ||
} catch (error) { | ||
console.error('Error logging in admin:'); | ||
} | ||
} | ||
|
||
async createAdmin(adminData) { | ||
try { | ||
const response = await this.httpClient.axiosInstance.post('/admins', adminData); | ||
return response.data; | ||
} catch (error) { | ||
console.error('Error creating admin:'); | ||
throw error; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import AdminsRepository from './AdminsRepository.js'; | ||
|
||
export default class AdminsService { | ||
constructor(httpClient) { | ||
this.adminsRepository = new AdminsRepository(httpClient); | ||
} | ||
|
||
async authenticateAdmin(adminData) { | ||
const response = await this.adminsRepository.authenticateAdmin(adminData); | ||
return response; | ||
} | ||
|
||
async createAdmin(adminData) { | ||
return await this.adminsRepository.createAdmin(adminData); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably remove that log.