-
Notifications
You must be signed in to change notification settings - Fork 14
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
NuroDev
wants to merge
8
commits into
main
Choose a base branch
from
authjs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
83dc1f9
Updated lock file
NuroDev 2a32f75
Added `astro-auth` & `@auth/core` dependencies
NuroDev a29ab71
Added `auth` integration to Astro config
NuroDev 40d6ec3
Added initial authentication setup
NuroDev de6786c
Added Auth.js Drizzle schemas
NuroDev c7912fe
Added migration to create Auth.js tables
NuroDev 06734dc
Added `@auth/drizzle-adapter` dependency
NuroDev 6fa4d0a
Added Drizzle adapter to Auth.js config
NuroDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Recommended: `openssl rand -hex 32` | ||
AUTH_SECRET="xxx" | ||
AUTH_TRUST_HOST=true | ||
|
||
GITHUB_CLIENT_ID="xxx" | ||
GITHUB_CLIENT_SECRET="xxx" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { defineConfig } from 'astro/config'; | ||
import tailwind from "@astrojs/tailwind"; | ||
|
||
import node from "@astrojs/node"; | ||
import auth from "auth-astro"; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({ | ||
output: 'server', | ||
integrations: [tailwind()], | ||
integrations: [tailwind(), auth()], | ||
adapter: node({ | ||
mode: "standalone" | ||
}) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import GitHub from '@auth/core/providers/github'; | ||
import { DrizzleAdapter } from '@auth/drizzle-adapter'; | ||
|
||
import { db } from './src/utils/db'; | ||
|
||
import type { AuthConfig } from '@auth/core'; | ||
|
||
export default { | ||
adapter: DrizzleAdapter(db), | ||
providers: [ | ||
GitHub({ | ||
clientId: import.meta.env.GITHUB_CLIENT_ID, | ||
clientSecret: import.meta.env.GITHUB_CLIENT_SECRET | ||
}) | ||
] | ||
} satisfies AuthConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
CREATE TABLE `account` ( | ||
`userId` text NOT NULL, | ||
`type` text NOT NULL, | ||
`provider` text NOT NULL, | ||
`providerAccountId` text NOT NULL, | ||
`refresh_token` text, | ||
`access_token` text, | ||
`expires_at` integer, | ||
`token_type` text, | ||
`scope` text, | ||
`id_token` text, | ||
`session_state` text, | ||
PRIMARY KEY(`provider`, `providerAccountId`), | ||
FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE `session` ( | ||
`sessionToken` text PRIMARY KEY NOT NULL, | ||
`userId` text NOT NULL, | ||
`expires` integer NOT NULL, | ||
FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE `user` ( | ||
`id` text PRIMARY KEY NOT NULL, | ||
`name` text, | ||
`email` text NOT NULL, | ||
`emailVerified` integer, | ||
`image` text | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE `verificationToken` ( | ||
`identifier` text NOT NULL, | ||
`token` text NOT NULL, | ||
`expires` integer NOT NULL, | ||
PRIMARY KEY(`identifier`, `token`) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,278 @@ | ||
{ | ||
"version": "5", | ||
"dialect": "sqlite", | ||
"id": "423155c6-ba31-49fe-a7d9-e4e9ee220ad1", | ||
"prevId": "97450856-16b2-42cd-8cb2-3e9b8ccda4f1", | ||
"tables": { | ||
"account": { | ||
"name": "account", | ||
"columns": { | ||
"userId": { | ||
"name": "userId", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"type": { | ||
"name": "type", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"provider": { | ||
"name": "provider", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"providerAccountId": { | ||
"name": "providerAccountId", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"refresh_token": { | ||
"name": "refresh_token", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"access_token": { | ||
"name": "access_token", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"expires_at": { | ||
"name": "expires_at", | ||
"type": "integer", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"token_type": { | ||
"name": "token_type", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"scope": { | ||
"name": "scope", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"id_token": { | ||
"name": "id_token", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"session_state": { | ||
"name": "session_state", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": { | ||
"account_userId_user_id_fk": { | ||
"name": "account_userId_user_id_fk", | ||
"tableFrom": "account", | ||
"tableTo": "user", | ||
"columnsFrom": [ | ||
"userId" | ||
], | ||
"columnsTo": [ | ||
"id" | ||
], | ||
"onDelete": "cascade", | ||
"onUpdate": "no action" | ||
} | ||
}, | ||
"compositePrimaryKeys": { | ||
"account_provider_providerAccountId_pk": { | ||
"columns": [ | ||
"provider", | ||
"providerAccountId" | ||
], | ||
"name": "account_provider_providerAccountId_pk" | ||
} | ||
}, | ||
"uniqueConstraints": {} | ||
}, | ||
"comments": { | ||
"name": "comments", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "integer", | ||
"primaryKey": true, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"author": { | ||
"name": "author", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"content": { | ||
"name": "content", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {} | ||
}, | ||
"session": { | ||
"name": "session", | ||
"columns": { | ||
"sessionToken": { | ||
"name": "sessionToken", | ||
"type": "text", | ||
"primaryKey": true, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"userId": { | ||
"name": "userId", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"expires": { | ||
"name": "expires", | ||
"type": "integer", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": { | ||
"session_userId_user_id_fk": { | ||
"name": "session_userId_user_id_fk", | ||
"tableFrom": "session", | ||
"tableTo": "user", | ||
"columnsFrom": [ | ||
"userId" | ||
], | ||
"columnsTo": [ | ||
"id" | ||
], | ||
"onDelete": "cascade", | ||
"onUpdate": "no action" | ||
} | ||
}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {} | ||
}, | ||
"user": { | ||
"name": "user", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "text", | ||
"primaryKey": true, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"name": { | ||
"name": "name", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"email": { | ||
"name": "email", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"emailVerified": { | ||
"name": "emailVerified", | ||
"type": "integer", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"image": { | ||
"name": "image", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {} | ||
}, | ||
"verificationToken": { | ||
"name": "verificationToken", | ||
"columns": { | ||
"identifier": { | ||
"name": "identifier", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"token": { | ||
"name": "token", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"expires": { | ||
"name": "expires", | ||
"type": "integer", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": { | ||
"verificationToken_identifier_token_pk": { | ||
"columns": [ | ||
"identifier", | ||
"token" | ||
], | ||
"name": "verificationToken_identifier_token_pk" | ||
} | ||
}, | ||
"uniqueConstraints": {} | ||
} | ||
}, | ||
"enums": {}, | ||
"_meta": { | ||
"schemas": {}, | ||
"tables": {}, | ||
"columns": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds the id field to the
session.user
object. Otherwise you wont retrieve the user id on