<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tanishk Kumar Shrivastava</title>
    <description>The latest articles on DEV Community by Tanishk Kumar Shrivastava (@tanishk_kumarshrivastava).</description>
    <link>https://dev.to/tanishk_kumarshrivastava</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1896560%2F311a59b0-8dd5-4eda-a476-812d831b8c19.jpeg</url>
      <title>DEV Community: Tanishk Kumar Shrivastava</title>
      <link>https://dev.to/tanishk_kumarshrivastava</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tanishk_kumarshrivastava"/>
    <language>en</language>
    <item>
      <title>Machine Learning Interview Series</title>
      <dc:creator>Tanishk Kumar Shrivastava</dc:creator>
      <pubDate>Sat, 10 Aug 2024 17:04:34 +0000</pubDate>
      <link>https://dev.to/tanishk_kumarshrivastava/machine-learning-interview-series-4el0</link>
      <guid>https://dev.to/tanishk_kumarshrivastava/machine-learning-interview-series-4el0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;From today onwards I am going to start my machine learning interview series. In this I will post 5 questions everyday till the whole syllabus is completed. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why to watch this series?
&lt;/h2&gt;

&lt;p&gt;If you are preparing for machine learning or data science interview or even for your university exams theory is so important. You know that you can implement the code but not able to explain what you have done in technical language. So this series is for you here you can learn concepts with the interview perspective how to convey the knowledge to the interviewer. &lt;/p&gt;

&lt;h2&gt;
  
  
  What will happen in this series?
&lt;/h2&gt;

&lt;p&gt;I am going to post 5 question everyday for six days a week and on Sunday we will revise the previous questions that I have mentioned.&lt;/p&gt;

&lt;p&gt;I will mention answers of the questions with practical implementation and the Mathematics if required.&lt;/p&gt;

&lt;h2&gt;
  
  
  How you can contribute to this series?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Let's say you have read a question in this series and you know more advanced version of the answer that I have mentioned you can comment on the post and I will edit the answer.&lt;/li&gt;
&lt;li&gt;You can suggest the questions which I will have to include in my next post.&lt;/li&gt;
&lt;li&gt;Share this series in your group.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>machinelearning</category>
      <category>interview</category>
      <category>datascience</category>
      <category>career</category>
    </item>
    <item>
      <title>Authentication system in Next.Js using Auth.js</title>
      <dc:creator>Tanishk Kumar Shrivastava</dc:creator>
      <pubDate>Fri, 09 Aug 2024 18:05:06 +0000</pubDate>
      <link>https://dev.to/tanishk_kumarshrivastava/authentication-system-in-nextjs-using-authjs-20g3</link>
      <guid>https://dev.to/tanishk_kumarshrivastava/authentication-system-in-nextjs-using-authjs-20g3</guid>
      <description>&lt;p&gt;Hey there, &lt;/p&gt;

&lt;p&gt;I was working on a project and then comes authentication part. Then I started searching for authentication library for nextjs rather than writing whole code by myself.&lt;/p&gt;

&lt;p&gt;Where I landed on this amazing library known as &lt;strong&gt;auth.js&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;So,&lt;br&gt;
Here I am going to share how to set up auth.js with next.js and importantly the errors which I came across. &lt;/p&gt;

&lt;p&gt;Let's get started:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1.&lt;/strong&gt; Setup the project :-&lt;/p&gt;

&lt;p&gt;Open your desired folder in terminal.&lt;br&gt;
Run &lt;code&gt;npx create-next-app@latest&lt;/code&gt; to create a next app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyk9xgh8p0ijnj68laji4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyk9xgh8p0ijnj68laji4.png" alt="Image description" width="648" height="468"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then cd into your app by &lt;code&gt;cd &amp;lt;your-app-name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This should look like this :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fezosr4kg9drde1jxgw7g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fezosr4kg9drde1jxgw7g.png" alt="Image description" width="800" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2.&lt;/strong&gt; Install auth.js library :-&lt;/p&gt;

&lt;p&gt;For npm users - &lt;code&gt;npm install next-auth@beta&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F89kd8ojw7mkrae8ub81h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F89kd8ojw7mkrae8ub81h.png" alt="Image description" width="704" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For yarn users - &lt;code&gt;yarn add next-auth@beta&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1fm5c47xqf5hrqinhmnj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1fm5c47xqf5hrqinhmnj.png" alt="Image description" width="704" height="242"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Error No 1 - Do not remove "beta" from the command
&lt;/h2&gt;

&lt;p&gt;I intentionally removed the beta part from the installation command because I don't want to install beta version but then I bumped into so many error like import error and file error. So don't remove the beta part.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3.&lt;/strong&gt; Setup auth secret key :-&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx auth secret&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fywbo8wixns05x9qqg1c4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fywbo8wixns05x9qqg1c4.png" alt="Image description" width="704" height="242"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will automatically adds a secret key named "AUTH_SECRET" in your .env.local file. &lt;/p&gt;

&lt;p&gt;AUTH_SECRET is a environment variable which is mandatory in auth.js.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd7zi71zrqnv21j1qvuib.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd7zi71zrqnv21j1qvuib.png" alt="Image description" width="800" height="22"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4.&lt;/strong&gt; Create a new auth.ts file in the root directory of your project.&lt;/p&gt;

&lt;p&gt;In my case its src directory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9gr93avqhcs4o3k39yql.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9gr93avqhcs4o3k39yql.png" alt="Image description" width="201" height="584"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add the following code to it :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import NextAuth from "next-auth"

export const { handlers, signIn, signOut, auth } = NextAuth({
  providers: [],
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5.&lt;/strong&gt; In your app folder create - &lt;code&gt;/api/auth/[...nextauth]/route.ts&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;Add the following code to it :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { handlers } from "@/auth" // Referring to the auth.ts we just created
export const { GET, POST } = handlers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6.&lt;/strong&gt; Create a new middleware.ts file in the root directory of your project.&lt;/p&gt;

&lt;p&gt;Add the following code to it :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export { auth as middleware } from "@/auth"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our initial setup is done. Now what we have to do is to setup authentication methods.&lt;/p&gt;

&lt;p&gt;There are three types of authentication methods available in auth.js library:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;OAuth&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Magic Links&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;WebAuthn&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this tutorial I am gonna use OAuth method. You can choose between various OAuth providers for this tutorial I am going with Github.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flfkiw6garj72bx1eucso.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flfkiw6garj72bx1eucso.png" alt="Image description" width="800" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7.&lt;/strong&gt; Go to &lt;code&gt;https://github.com/settings/profile&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffxwe7lw9g9d9vrusgvsd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffxwe7lw9g9d9vrusgvsd.png" alt="Image description" width="800" height="435"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On left navigation bar scroll down and select Developer Settings.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkr82irl64g0e7t4095ht.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkr82irl64g0e7t4095ht.png" alt="Image description" width="284" height="277"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then click on OAuth apps. And create New OAuth App.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F40j85w4fzrdd62szee3i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F40j85w4fzrdd62szee3i.png" alt="Image description" width="800" height="198"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From there you get your client id and client secret.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 8.&lt;/strong&gt; Create .env.local file in the root directory of your project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9vodtm0rkonqknw3xrfo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9vodtm0rkonqknw3xrfo.png" alt="Image description" width="187" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add the following environment variables to it :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AUTH_GITHUB_ID=&amp;lt;client-id-from-step7&amp;gt;
AUTH_GITHUB_SECRET=&amp;lt;client-secret-from-step7&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Do not change the name of the variables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 9.&lt;/strong&gt; Add the Github Provider in auth.js file &lt;code&gt;@/auth.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import NextAuth from "next-auth"
import GitHub from "next-auth/providers/github"

export const { handlers, signIn, signOut, auth } = NextAuth({
  providers: [GitHub],
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 10.&lt;/strong&gt; Create component folder inside src folder and add a SignInBtn.tsx component file to it. You can name it as you want.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiq1a7nmu7roa6w59574z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiq1a7nmu7roa6w59574z.png" alt="Image description" width="201" height="584"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add the following code to it :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { signIn } from "@/auth"

export default function SignIn() {
  return (
    &amp;lt;form
      action={async () =&amp;gt; {
        "use server"
        await signIn("github")
      }}
    &amp;gt;
      &amp;lt;button type="submit"&amp;gt;Signin with GitHub&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also style the button as you want it to be.&lt;/p&gt;

&lt;p&gt;Now use this button wherever you want.&lt;/p&gt;

&lt;h2&gt;
  
  
  Error No 2 - Do not use the button inside the page or component which is using "use client" property.
&lt;/h2&gt;

&lt;p&gt;I used this button inside a component which is rendering on client side. If you carefully see the button code we are using "use server" in it, so it gives me error that I cannot use server service in the client side rendering. So be careful in it. &lt;/p&gt;

&lt;p&gt;Enjoy.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>authjs</category>
      <category>typescript</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
