Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Auth.js based authentication #2

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

Added Auth.js based authentication #2

wants to merge 8 commits into from

Conversation

NuroDev
Copy link
Collaborator

@NuroDev NuroDev commented Jan 3, 2024

What's been changed?

  • Added astro-auth integration
    • Created Auth.js config (auth.config.ts) with GitHub provider by default + Drizzle database adapter
    • Added dependencies
      • @auth/core
      • @auth/drizzle-adapter
      • auth-astro
    • Added Auth.js schemas to Drizzle
    • Added types for the new schemas added above
    • Added new migration to add schemas / tables required for authentication
    • Added sign out button to CommentForm component
    • Added new /login page
    • Homepage now redirects to /login if not logged in
  • Added basic .example.env with template environment variables
  • Added a defaultName prop to CommentForm component
  • Added custom environment variable types to env.d.ts

@NuroDev NuroDev added the enhancement New feature or request label Jan 3, 2024
@NuroDev NuroDev requested a review from Sh4yy January 3, 2024 17:15
@NuroDev NuroDev self-assigned this Jan 3, 2024
@NuroDev
Copy link
Collaborator Author

NuroDev commented Jan 3, 2024

I've just realised that the README.md may also need updating in relation to the environment variables.

Shall we add the REPLICA_URL, LITESTREAM_ACCESS_KEY_ID & LITESTREAM_SECRET_ACCESS_KEY environment variables to the .example.env? And/or update the README.md to tell people how to use the .example.env instead?

Copy link

@julianfbeck julianfbeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, Thanks for your pr! I wanted to use auth with lazy stack and found your open PR :)

i just testet it and needed to adjust a view things to get it working for me :)

clientId: import.meta.env.GITHUB_CLIENT_ID,
clientSecret: import.meta.env.GITHUB_CLIENT_SECRET
})
]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
]
],
callbacks: {
session({ session, user }) {
if (session.user) {
session.user.id = user.id;
}
return session;
}
}

This adds the id field to the session.user object. Otherwise you wont retrieve the user id on

Comment on lines +26 to +28
(account) => ({
compoundKey: primaryKey(account.provider, account.providerAccountId)
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(account) => ({
compoundKey: primaryKey(account.provider, account.providerAccountId)
})
(account) => ({
compoundKey: primaryKey({
columns: [account.provider, account.providerAccountId]
})
})

token: text('token').notNull(),
expires: integer('expires', { mode: 'timestamp_ms' }).notNull()
},
(vt) => ({ compoundKey: primaryKey(vt.identifier, vt.token) })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(vt) => ({ compoundKey: primaryKey(vt.identifier, vt.token) })
(vt) => ({
compoundKey: primaryKey({ columns: [vt.identifier, vt.token] })
})```

"astro": "^4.0.8",
"auth-astro": "^4.1.0",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"auth-astro": "^4.1.0",
"auth-astro": "^4.1.1",

@@ -14,7 +14,10 @@
"@astrojs/check": "^0.3.4",
"@astrojs/node": "^7.0.3",
"@astrojs/tailwind": "^5.1.0",
"@auth/core": "^0.18.6",
"@auth/drizzle-adapter": "^0.3.12",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"@auth/drizzle-adapter": "^0.3.12",
"@auth/drizzle-adapter": "^0.5.0",

I had to update this adapter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants