gitlab-auth
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

GitLab Auth helper for React

import { GitlabAuth, useGitlab } from "gitlab-auth";

function App() {
  return (
    <GitlabAuth
      host="https://gitlab.example.com/"
      application_id="xxxx(Application ID setup in your gitlab instance as admin under applications)xxx"
      redirect_uri="http://localhost:3000/auth/"
      scope="api openid profile email"
    >
      <>This is rendered with GitLab access!</>
    </GitlabAuth>
  );
}

To get access to the gitlab API and list branches:

import { useState, useEffect } from "react";
import { useGitlab } from "gitlab-auth";

function BranchesList() {
  const [branches, setBranches] = useState(null);
  const gitlab = useGitlab();
  useEffect(() => {
    gitlab.Branches.all("myprojectname").then((b) => {
      setBranches(b);
    });
  }, [gitlab]);
  return (
    <>
      {branches &&
        branches.map((branch, idx) => {
          <div key={idx}>{branch.name}</div>;
        })}
    </>
  );
}

Readme

Keywords

Package Sidebar

Install

npm i gitlab-auth

Weekly Downloads

9

Version

0.2.0

License

MIT

Unpacked Size

3.21 kB

Total Files

3

Last publish

Collaborators

  • sandercox