Code Monkey home page Code Monkey logo

start-oauth's Introduction

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.

start-oauth's People

Contributors

thomasbuilds avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.