0.0.14-beta.10 β€’ Published 8 months ago

worker-auth-providers v0.0.14-beta.10

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

πŸš€ Demo

Try now

🧐 Features

  • Open Source
  • Fast & Lightweight
  • Easy

πŸ› οΈ Installation

Step 1: Install the dependencies

npm install worker-auth-providers

Step 2: Import the dependencies

import {
  github, google,
  twilio, facebook, discord,
  spotify
} from "worker-auth-providers";

Step 3: Redirect users

const githubLoginUrl = await github.redirect({
    options: {
        clientId,
    },
});
return {
    status: 302,
    headers: {
        location: githubLoginUrl,
    },
};

// or send otp

const res = await awsSNS.send({
  options: {
    phone,
    region: 'ap-south-1',
    kvProvider: WORKER_AUTH_PROVIDERS_STORE,
  },
})

Step 4: Get user

const { user: providerUser, tokens } = await github.users({
    options: { clientSecret, clientId },
    request,
});
console.log("[providerUser]", providerUser);

// or verify otp
const res = await awsSNS.verify({
  options: {
    phone,
    otp,
    kvProvider: WORKER_AUTH_PROVIDERS_STORE,
    secret: 'eyJhbGciOiJIUzI1NiJ9.ew0KICAic3ViIjogIjE2Mjc4MTE1MDEiLA0KICAibmFtZSI6ICJoYWFsLmluIiwNCiAgImlhdCI6ICIwMTA4MjAyMCINCn0.aNr18szvBz3Db3HAsJ-2KHYbnnHwHfK65CiZ_AWwpc0',
  },
})

πŸ“ƒ Documentation

Coming soon

πŸ‘©β€πŸ’» Tech

🍰 Contributing

Contributions are always welcome! See contributing.md for ways to get started. Please adhere to this project's code of conduct.

Roadmap

  • Docs.
  • Apple.
  • Azure (Microsoft)
  • Google.
  • Github
  • OTP Twilio
  • Mailgun Email
  • Sendgrid Email
  • Facebook
  • Discord
  • Instagram
  • Amazon
  • Twitter
  • Spotify
  • Auth0

##FAQs

How to persist login?

Use cookie. Setting a cookie to indicate that they’re authorized for future requests

const cookieKey = "worker-auth-providers"
const persistAuth = async exchange => {
    const date = new Date()  date.setDate(date.getDate() + 1)
    const headers = { 
      Location: "/",
      "Set-cookie": `${cookieKey}=${id}; Secure; HttpOnly; SameSite=Lax; Expires=${date.toUTCString()}`,
    }
    return { headers, status: 302 }
}

How to logout?

Easy, delete the cookie

export const logout = event => {
  const cookieHeader = event.request.headers.get('Cookie')
  if (cookieHeader && cookieHeader.includes(cookieKey)) {
    return {
      headers: {
        'Set-cookie': `${cookieKey}=""; HttpOnly; Secure; SameSite=Lax;`,
      },
    }
  }
  return {}
}

Feedback

If you have any feedback, please reach out to me at subhendukundu14@gmail.com

✍️ Authors

πŸ’Ό License

MIT

0.0.14-beta.3

8 months ago

0.0.14-beta.4

8 months ago

0.0.14-beta.5

8 months ago

0.0.14-beta.6

8 months ago

0.0.14-beta.7

8 months ago

0.0.14-beta.8

8 months ago

0.0.14-beta.9

8 months ago

0.0.14-beta.10

8 months ago

0.0.14-beta.1

8 months ago

0.0.14-beta.2

8 months ago

0.0.14

8 months ago

0.0.13-beta.2

2 years ago

0.0.13-beta.1

2 years ago

0.0.13-beta.4

2 years ago

0.0.13-beta.3

2 years ago

0.0.10-beta13

2 years ago

0.0.10-beta14

2 years ago

0.0.10-beta15

2 years ago

0.0.11

2 years ago

0.0.12

2 years ago

0.0.13

2 years ago

0.0.10-beta12

2 years ago

0.0.10-beta17

2 years ago

0.0.10-beta10

2 years ago

0.0.10-beta11

2 years ago

0.0.10-beta7

3 years ago

0.0.10-beta8

2 years ago

0.0.10-beta9

2 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6-beta.3

4 years ago

0.0.6-beta.2

4 years ago

0.0.6-beta.1

4 years ago

0.0.6-beta.0

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago