Code Monkey home page Code Monkey logo

t3-sandbox's Introduction

About

My name is Shumayl, and I like to tinker with software.

  • ๐Ÿข Currently working on platform engineering at Deloitte Global.
  • ๐Ÿค– Previously worked on digital transformation and application modernization at HP Inc.
  • โšก๏ธ Graduated with a BSc. in Physics from Universiti Teknologi PETRONAS.

Tinkerings

  • ๐Ÿ› ๏ธ I built AI-Daleel to make it easier for me to search for Quranic verses.
  • โš™๏ธ I write technical articles on my personal site.
  • ๐Ÿ’ป I talk about software and tech on LinkedIn.

t3-sandbox's People

Contributors

mshumayl avatar

Stargazers

 avatar

Watchers

 avatar

t3-sandbox's Issues

Add more sign-in options

Objective

To learn how to use NextAuthJS by adding more sign-in options. This Issue will serve as my notebook as I try to grok this.

Suggestions

I believe there are three things I should learn here:

  • Adding sign-in options from other auth providers.
  • Adding custom sign-in option.
  • Configuring roles.
  • Securing routes.

Q&A

Updating this section as I learn.

1. How to implement role-based authorization?

2. Can Prisma handle user-role logic?

  • Prisma does not handle user-role logic per se, but you use Prisma to define a role field in the Users model.
  • You then query the database via Prisma to get the role of the current user.
  • After storing this value in the session object from NextAuth.js, where you can decide if a user has the right role for any request.
  • You also use Prisma for code that elevates/changes a user's role, but optimally, a superuser needs to be defined through direct database access.

3. How to override the default auth page from NextAuth.js?

  • This can be customized by creating a signin.tsx page and registering it in [...nextauth.js] config with the pages key as below:
export const authOptions: NextAuthOptions = {
  // Include user.id on session
  callbacks: {
    session({ session, user }) {
      if (session.user) {
        session.user.id = user.id;
      }
      return session;
    },
  },
  // Configure one or more authentication providers
  adapter: PrismaAdapter(prisma),
  providers: [
    DiscordProvider({
      clientId: env.DISCORD_CLIENT_ID,
      clientSecret: env.DISCORD_CLIENT_SECRET,
    }),
    // ...add more providers here
    GithubProvider({
      clientId: env.GITHUB_CLIENT_ID,
      clientSecret: env.GITHUB_CLIENT_SECRET,
    }),
  ],
  pages: {
    signIn: "/signin",  // Add custom sign in page location here
  }
};

export default NextAuth(authOptions);

Configure tRPC API routes

Objective

To learn tRPC routing by tweaking endpoints.

Suggestion

  • UPDATE: Migrate to version 7.3.0
  • Start by passing posts data in the Admin page through a secured API call.

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.