1.1.0 • Published 19 days ago

start-oauth v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
19 days ago

OAuth2 for SolidStart

NPM

This package returns the name, email and image of user authenticated through third party services (supporting Discord, GitHub, Google and Spotify as of now).

Installation

# npm
npm install start-oauth

# pnpm
pnpm add start-oauth

Configuration

//MUST BE api/oauth/[...oauth].ts
import OAuth, { type Configuration } from "start-oauth";

const configuration: Configuration = {
  google: {
    id: process.env.GOOGLE_ID as string,
    secret: process.env.GOOGLE_SECRET as string,
    state: process.env.STATE, //optional XSRF protection
  },
  async handler(user, redirect) {
    //create user session
  },
};

export const GET = OAuth(configuration);
  • In case of error, you are redirected to page requesting login and error parameter specifies reason.
  • Adding a redirect search parameter on page requesting login gives you access to the value on handler function.
//login.tsx for example
export default function Login() {
  const requestLogin = useOAuthLogin();

  return (
    <div>
      <a href={requestLogin("google")} rel="external">
        <GoogleIcon />
      </a>
    </div>
  );
}

The package doesn’t provide the session management. This gives you complete control over redirections and you can seamlessly integrate multiple authentication methods sharing the same logic.

Contributions

Please open issues for bugs and we much appreciate contributions for more provider support.

1.1.0

19 days ago

1.0.5

22 days ago

1.0.2

22 days ago

1.0.1

22 days ago

1.0.0

22 days ago