open-sauced / hot

πŸ•The site that recommends the hottest projects on GitHub.
https://hot.opensauced.pizza
MIT License
422 stars 147 forks source link

Need Open Sauced GitHub Login #20

Closed bdougie closed 2 years ago

bdougie commented 2 years ago

Type of feature

Feature

Current behavior

The user profile is currently a placeholder. Need a GitHub login to confirm the following

image

Desired solution

We can mirror the logging from github.com/bdougie/live or github.com/open-sauced/open-sauced

  1. Add login functionally to the Astro app
  2. Replaces the Generic Avatar with the logged in user Avatar

Additional context

The open sauced login is powered by a GitHub App Id

Code of Conduct

bdougie commented 2 years ago

Doing some light research and think Netlify with is the way to go here.

https://docs.netlify.com/visitor-access/identity/

0-vortex commented 2 years ago
Screenshot 2021-12-19 at 03 30 23

Have used it in some demos to emulate GitHub login with multiple headless CMS - in those setups nothing was managed by Netlify, all the rights being handled by GitHub repository access rights, IE if you had push access to the repo you could commit the changes.

Not a big fan of frontend stuff but could maybe pick this up if you are not rushing too much!

nulfrost commented 2 years ago

I can take a look at this, there might need to be some things set up on the netlify end but if that's good to go I'll start working on this as soon as I can

nulfrost commented 2 years ago

.take

github-actions[bot] commented 2 years ago

Thanks for taking this on! If you have not already, join the conversation in our Discord

bdougie commented 2 years ago

I setup Netlify Identity with custom GitHub OAuth:

endpoint: https://hot.opensauced.pizza/.netlify/identity

bdougie commented 2 years ago

Some more context. Login and Logout should be linked in the nav. This can be addressed in this issue or a future, just leaving here for context. Font awesome codes are below.

fa-sign-in login

fa-sign-out logout

nulfrost commented 2 years ago

Screen Shot 2021-12-25 at 1 52 01 PM

Making some progress πŸ‘πŸΏ is there a way to only show the github login button on the widget? doing some google searching but haven't found anything yet

bdougie commented 2 years ago

I don't think that is possible without creating a new (fork) widget. Using GoTru directly is what supabase is doing as well.

But for the sake of keeping the scope small, leaving the email in, for now, is fine. I may explore supabase for this in the future to simplify things.

nulfrost commented 2 years ago

Hey! So picking up on this again and getting this error when trying to log in with github Screen Shot 2022-01-04 at 8 41 50 PM

the link it is referring to leads here https://docs.onegraph.com/docs/authentication.html#asking-your-user-to-sign-in

and another relevant error Screen Shot 2022-01-04 at 8 51 59 PM

As I was typing this I kind of figured maybe the redirect url / callback url are probably configured for the live site and not localhost? if so then I have most of the code already done and would just need to test in the live environment. Let me know what you think

bdougie commented 2 years ago

Sorry about that I gave you the oauth for opensauced.pizza which redirects to the onegraph AuthGuardian service. I just created a new GitHub service specifically for this project. If you try again it should redirect to NEtlify and authorize from there.

https://docs.netlify.com/visitor-access/oauth-provider-tokens/

Screen Shot 2022-01-05 at 2 57 54 PM

nulfrost commented 2 years ago

Hmm, still seem to be facing errors related to authentication. I've read and double-checked the documentation for the widget but I don't think I'm missing anything πŸ€”

Here are some of the errors I've encountered Screen Shot 2022-01-07 at 7 17 19 PM

and this one is the same from the last post Screen Shot 2022-01-07 at 7 17 45 PM

also I'm not sure if this is relevant or not but here's the code I implemented for the github auth stuff

import { useState, useEffect } from "react";
import netlifyIdentity from "netlify-identity-widget";

export const useNetlifyAuth = () => {
  const [user, setUser] = useState(null);

  useEffect(() => {
    netlifyIdentity.init();
    setUser(netlifyIdentity.currentUser());
  }, [user]);

  return {
    user,
    login: netlifyIdentity.open,
  };
};

I don't think I'm missing anything but here's the branch I'm currently working on too if you wanted to take a look, https://github.com/nulfrost/hot/tree/add-github-login

bdougie commented 2 years ago

unrelate note: Tried running your branch locally and getting a "esbuild-darwin-arm64" error. I needed to remove it to get it to work. Curious what that was for. Are you working in a Linux environment that needed that?

netlify-identity will not work

I don't we will be able to use the netlfy identity widget. The requirement to have email is also weird for this use case of github login. I did some quick searching and ran into this thread https://github.com/netlify/gotrue/issues/114#issuecomment-362004553. Basically, we should be leaning on the go-true service instead. Luckily supabase already integrates that into its service. The changes implemented #67 include supabase-js and Netlify.

supabase-auth is the solution

Thank you for running through this, but supabase + github is the way to go on this. It will provide us role-level security with the DB and has a lot of community support.

Since the keys are already embedded in the database.js, you can use that to add login. You may want to refactor that or leverage your auth files instead.

//login session can be added to your custom hook 
async function signInWithGithub() {
  const { user, session, error } = await supabase.auth.signIn({
    provider: 'github',
  })
}

//logout
async function signout() {
  const { error } = await supabase.auth.signOut()
}

Ironically, I stumbled on this article while researching all this, which wasn't helpful since it is 5+ years old. https://www.netlify.com/blog/2017/10/30/how-to-add-netlify-identity-service-to-react-projects/ t

nulfrost commented 2 years ago

unrelate note: Tried running your branch locally and getting a "esbuild-darwin-arm64" error. I needed to remove it to get it to work. Curious what that was for. Are you working in a Linux environment that needed that?

Working on an M1 macbook, for some reason without it I wasn't able to start the dev server

netlify-identity will not work

I don't we will be able to use the netlfy identity widget. The requirement to have email is also weird for this use case of github login. I did some quick searching and ran into this thread netlify/gotrue#114 (comment). Basically, we should be leaning on the go-true service instead. Luckily supabase already integrates that into its service. The changes implemented #67 include supabase-js and Netlify.

supabase-auth is the solution

Thank you for running through this, but supabase + github is the way to go on this. It will provide us role-level security with the DB and has a lot of community support.

Since the keys are already embedded in the database.js, you can use that to add login. You may want to refactor that or leverage your auth files instead.

//login session can be added to your custom hook 
async function signInWithGithub() {
  const { user, session, error } = await supabase.auth.signIn({
    provider: 'github',
  })
}

//logout
async function signout() {
  const { error } = await supabase.auth.signOut()
}

Ironically, I stumbled on this article while researching all this, which wasn't helpful since it is 5+ years old. https://www.netlify.com/blog/2017/10/30/how-to-add-netlify-identity-service-to-react-projects/ t

Sweet! I'll take a look at this tonight, I've worked with supabase before so it's all very familiar

0-vortex commented 2 years ago

Make sure you have node>=14 and npm@8 and then do this:

git restore package.json npm-shrinkwrap.json -s upstream/main
npm ci
npm install --save netlify-identity-widget

If you did not clone with gh cli, replace upstream/main with origin/main to get the changes from your own fork.

That should fix all the issues with dependencies! πŸ•

github-actions[bot] commented 2 years ago

:tada: This issue has been resolved in version 1.10.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: