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

User authentication #2

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

User authentication #2

wants to merge 15 commits into from

Conversation

Limeload
Copy link
Owner

@Limeload Limeload commented Aug 4, 2023

Step 1: Set Up Firebase

  1. Create a Firebase project:

  2. Set up Firebase Authentication:

    • In the Firebase Console, navigate to "Authentication" from the left menu.
    • Click "Set up sign-in method" and enable the authentication providers you want to use (e.g., Google, Email/Password).
  3. Get Firebase Configuration:

    • In the Firebase Console, go to Project Settings (gear icon) > General.
    • Scroll down to the "Your apps" section and click "Config" to reveal your Firebase configuration object.

Step 2: Frontend Integration

  1. Install the Firebase SDK in your Vue.js frontend:

    npm install firebase
  2. Set up Firebase in your Vue.js app:

    • Create a firebase.js file in your src directory.
    • Paste the Firebase configuration object from Step 1:
      import firebase from 'firebase/app';
      import 'firebase/auth';
      
      const firebaseConfig = {
        apiKey: "YOUR_API_KEY",
        authDomain: "YOUR_AUTH_DOMAIN",
        projectId: "YOUR_PROJECT_ID",
        storageBucket: "YOUR_STORAGE_BUCKET",
        messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
        appId: "YOUR_APP_ID"
      };
      
      firebase.initializeApp(firebaseConfig);
      const auth = firebase.auth();
      
      export { firebase, auth };
  3. Use Firebase Authentication in your Vue components:

    • Import auth from your firebase.js file and use it to manage authentication state, sign-in, sign-out, etc.

Step 3: Backend Integration

  1. Secure Backend Endpoints (Optional):
    • If your backend has APIs that require authentication, you can implement middleware to verify Firebase tokens.

Step 4: User Experience

  1. Design and implement user registration and login interfaces in your Vue.js app.

  2. Use Firebase authentication methods to register and sign in users.

Step 5: Testing and Deployment

  1. Test user authentication thoroughly to ensure it's working as expected.

  2. Deploy your Vue.js frontend and Node.js backend to your hosting provider.

@Limeload Limeload requested a review from Irishwolf13 October 10, 2023 20:48
Copy link
Collaborator

@Irishwolf13 Irishwolf13 left a comment

Choose a reason for hiding this comment

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

Hard for me to review this one, as I'm not up to speed on vue. As far as I can tell, code looks good.

@dlardo
Copy link
Collaborator

dlardo commented Oct 11, 2023

There are 1800+ files here. Do we really need to vendor our dependencies?
If you feel strongly about it, please put those files in another PR and keep this one to only the code we created.

@Limeload Limeload requested a review from dlardo October 11, 2023 00:58
@Limeload
Copy link
Owner Author

There are 1800+ files here. Do we really need to vendor our dependencies?
If you feel strongly about it, please put those files in another PR and keep this one to only the code we created.

@dlardo Resolved

Copy link
Collaborator

@dlardo dlardo left a comment

Choose a reason for hiding this comment

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

Left you some things to consider

// Broadcast messages to all connected clients
socket.on('draw', (data) => {
// Store data in Redis
redisClient.set('drawData', JSON.stringify(data));
Copy link
Collaborator

Choose a reason for hiding this comment

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

If horizontal scalability isn't a goal then I would keep the data local. Redis is going to add additional complexity without adding any benefit.

// More event handling here
});

const port = 3000;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would consider putting this into a config file or an environment variable.

const auth = getAuth();

const login = () => {
signInWithEmailAndPassword(auth, email.value, password.value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would consider going only with Google (or other Oauth providers). Building and maintaining code, and protecting personal information and passwords is a lot of responsibility and effort. "Google says this is a person" is probably good enough for this app's needs.


// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyCY_lHHHSAjhGq7no6ETe4002WQIa5Cx7s",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is probably fine for this project but in general you don't want to commit apiKeys, they are your app's passwords. I would consider putting this in a config file and reading the API key from it. Typically teams will use a shared secret manager like Lastpass, or use something like https://pwpush.com/ to send the secret around.

const currentUser = auth.currentUser;

// Check if the route requires authentication
if (to.matched.some((record) => record.meta.requiresAuth)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider rewriting this block so it's flatter (more left aligned). The else statements are almost always next(); so following the code would be better if you had a flow similar to this:

if (!auth) { go auth() };
if (!bogusUrl) { go fish() }
if (some other things that could go wrong...)

// Happy path
next();

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.

3 participants