Skip to content
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

CE-1262 Set up authentication page #6

Merged
merged 34 commits into from
Sep 13, 2021

Conversation

Nutto55
Copy link
Contributor

@Nutto55 Nutto55 commented Sep 6, 2021

βœ… DoD

  • Resolve CE-1262 and 1348
  • Documentation updated
  • CHANGELOG updated

πŸ“ Summary

  • Add auth0 to the project
  • Add vuex to store data into state
  • Set up vuex store and services style

πŸ“Έ Screenshots

20210906_232555

πŸ›‘ Problems

  • I think this project use many new tool which not familiar (e.g. windicss, vue3, vite, etc.), so it consume both time to learn and implement.
  • I'm considering to use windicss ui component e.g. daisyUI, but probably giving a chance to try windicss more before design about this choice or we can have a discussion with team who based on this project.

πŸ’‘ More ideas

  • I store user and auth into vuex store after project init because with that way I may config axios base api module for this project easier.
  • I have considering store tool between vuex and pinia and end up with vuex because I am more familiar with this tool + vuex is implement well to support vue 3 in my opinion.
  • Adding loading component to be global component

Copy link
Member

@antonyharfield antonyharfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor point on the env vars...

README.md Outdated Show resolved Hide resolved
src/auth/config.json Outdated Show resolved Hide resolved
<style>
#preload {
position: fixed;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about config this with Windi?

Screen Shot 2564-09-10 at 14 34 25

https://windicss.org/utilities/positioning.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't work there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can try to change this one. You will see overlapping white screen.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect you shouldn't be using Windicss classes in index.html.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used it and it seem to be ok except class fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nutto55 - Did you test is locally where the scripts load instantly or over a slow connection? I don't think you're testing the problem I'm expecting.

# Conflicts:
#	CHANGELOG.md
#	package-lock.json
#	package.json
#	src/models/Stream.ts
#	src/models/index.ts
#	src/pages/root/root.html
#	src/pages/species-richness/species-richness.ts
#	windi.config.ts
Comment on lines +27 to +29
document.getElementById('preload').style.visibility = 'visible'
document.getElementById('app').style.visibility = 'hidden'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure about the sequence here...

  • Isn't #preload already visible?
  • Shouldn't #app already be hidden? (why not set hidden on app directly in the HTML?)
  • Aren't the Windicss classes on #preload embedded in main.ts? At this point external styles & scripts are still loading

index.html Outdated Show resolved Hide resolved
src/App.vue Outdated Show resolved Hide resolved
Comment on lines +1 to +5
export default {
domain: 'auth.rfcx.org',
clientId: 'LiojdvNUserGnCaLj8ckcxeGPHOKitOc',
audience: 'https://rfcx.eu.auth0.com/api/v2/'
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be in .env or private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It don't have to.

src/App.vue Outdated Show resolved Hide resolved
const Auth0Plugin = await Auth0.init({
redirectUri: window.location.origin,
onRedirectCallback: (appState) => {
void router.push(appState?.targetUrl ?? window.location.pathname)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void router-push(...)

This is cool. I could never get this working! I think it's because I've be using arrow functions.

export const Auth0: Auth0Plugin = {
init,
routeGuard
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How confident are you that this file is correct?
I don't envy you having to write this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The start script is from official example which is in vue2 and got migrate to vue3 by him: https://github.com/alexeyzimarev/auth0-vue3-ts/tree/master/src. I have try to write it in another way e.g. class based or group them in a function but it is too complicated. Maybe you have a better idea to refactor auth0 config.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not without spending a long time on it. Maybe we should review this in the future. Hopefully Auth0 will publish an "official" Vue 3 solution.

src/models/Navbar.ts Outdated Show resolved Hide resolved
</div>
<div class="flex items-center mx-4">
<button
v-if="!auth?.isAuthenticated"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you avoid auth being null/undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because initial value of Auth in vuex is undefined which is the same as value when user haven't authenticate yet.

Copy link
Contributor

@charles-allen charles-allen Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is auth the Auth0 object? I don't think that should be in Vuex.

Or is it a user?

FYI - I think Vue doesn't like undefined for Reactive fields. You might need to use null. Or maybe that's only a Vue 2 issue.

url: string
}

const CORE = 'https://staging-api.rfcx.org'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in .env

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, It should be another separate task for setting the env for staging, production, etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add it to the PB?

Copy link
Contributor Author

@Nutto55 Nutto55 Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Added it.

Comment on lines +12 to +17
const Auth0Plugin = await Auth0.init({
redirectUri: window.location.origin,
onRedirectCallback: (appState) => {
void router.push(appState?.targetUrl ?? window.location.pathname)
}
})
Copy link
Contributor

@charles-allen charles-allen Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not keen on making the auth plugin here. This logic should be extracted. You could import createAuthPlugin so that you can still pass in the router, default URL, etc.

src/models/Auth.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@charles-allen charles-allen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is an outstanding issue, I would say it's this one: #6 (comment). I'm unfamiliar with Auth0 code (and I'm suspicious that maybe no one else has reviewed it either). Maybe we can discuss it after I start proper.

Other than that, I wrote a lot & learned quite a lot :) But all my comments are either questions or tips. I don't think there's anything blocking merge, so I will approve.

@Nutto55 Nutto55 merged commit 74fce40 into develop Sep 13, 2021
@Nutto55 Nutto55 deleted the feature/CE-1262-set-up-authentication-page branch September 13, 2021 10:22
@koonchaya koonchaya mentioned this pull request Mar 3, 2023
40 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants