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

feat: add @auth/astro framework library with example & docs #6463

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3bfa740
feat: add astro package and example
TheOtterlord Jan 16, 2023
19862de
feat: add astro components
TheOtterlord Jan 16, 2023
5cb2c39
docs: record usage of astro auth
TheOtterlord Jan 16, 2023
7c77017
fix: move astro components to separate file
TheOtterlord Jan 17, 2023
326bdbb
Update index.md
tajkirkpatrick Jan 17, 2023
9969199
Apply suggestions from code review
tajkirkpatrick Jan 17, 2023
e072d8e
fix: pass provider data to client
TheOtterlord Jan 17, 2023
ecbc4e5
Merge pull request #1 from tajkirkpatrick/patch-1
TheOtterlord Jan 17, 2023
d106209
docs: astro client & component reference
TheOtterlord Jan 17, 2023
dad2a9f
feat: make provider optional
nowaythatworked Jan 17, 2023
949313e
feat: initialise trustHost based on env vars
nowaythatworked Jan 17, 2023
4007f04
chore: explain ignoring of error
nowaythatworked Jan 17, 2023
2cc6868
Merge pull request #3 from nowaythatworked/improvements
TheOtterlord Jan 17, 2023
b713441
fix: addtl check and remove extra env
tajkirkpatrick Jan 18, 2023
2a9bdd6
docs: up and running instructions
tajkirkpatrick Jan 18, 2023
2f108bd
chore(docs): phrasing
tajkirkpatrick Jan 18, 2023
18e0de2
chore(docs): expand example and more phrasing
tajkirkpatrick Jan 18, 2023
f97a1ba
Update index.md
tajkirkpatrick Jan 18, 2023
47bef7e
Merge pull request #4 from tajkirkpatrick/docs
TheOtterlord Jan 18, 2023
57595e3
chore: improve readability
nowaythatworked Jan 18, 2023
7acaca5
chore: add missing package
nowaythatworked Jan 18, 2023
e2f6658
Merge pull request #5 from nowaythatworked/main
TheOtterlord Jan 18, 2023
a8837dd
chore: modify handler
TheOtterlord Jan 18, 2023
da91703
fix: respect prefix in client methods & getsession
TheOtterlord Jan 18, 2023
d04e3f2
fix: astro auth support node 17.4.0 and higher
TheOtterlord Jan 19, 2023
5d62514
fix: weird behaviour in vercel serverless
TheOtterlord Jan 21, 2023
7787bd5
fix: signout component in vercel serverless
TheOtterlord Jan 21, 2023
09de9a2
Merge branch 'main' of https://github.com/TheOtterlord/authjs
TheOtterlord Jan 22, 2023
64df70d
docs: document astro auth
TheOtterlord Jan 26, 2023
fb040d9
docs: fix package name
TheOtterlord Jan 26, 2023
38703b8
feat(astro): upgrade to use the integration api
TheOtterlord Mar 14, 2023
bfd5ab1
docs(astro): update astro docs
TheOtterlord Mar 14, 2023
3783abf
docs(astro): update astro docs
TheOtterlord Mar 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ packages/core/providers
packages/core/src/lib/pages/styles.ts
docs/docs/reference/03-core
docs/docs/reference/04-sveltekit
docs/docs/reference/04-astro


# SvelteKit
Expand Down
20 changes: 20 additions & 0 deletions apps/examples/astro/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# build output
dist/
.output/

# dependencies
node_modules/

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*


# environment variables
.env
.env.production

# macOS-specific files
.DS_Store
4 changes: 4 additions & 0 deletions apps/examples/astro/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"recommendations": ["astro-build.astro-vscode"],
"unwantedRecommendations": []
}
11 changes: 11 additions & 0 deletions apps/examples/astro/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "./node_modules/.bin/astro dev",
"name": "Development server",
"request": "launch",
"type": "node-terminal"
}
]
}
49 changes: 49 additions & 0 deletions apps/examples/astro/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Welcome to [Astro](https://astro.build)

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/basics)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/s/github/withastro/astro/tree/latest/examples/basics)

> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun!

![basics](https://user-images.githubusercontent.com/4677417/186188965-73453154-fdec-4d6b-9c34-cb35c248ae5b.png)

## 🚀 Project Structure

Inside of your Astro project, you'll see the following folders and files:

```
/
├── public/
│ └── favicon.svg
├── src/
│ ├── components/
│ │ └── Card.astro
│ ├── layouts/
│ │ └── Layout.astro
│ └── pages/
│ └── index.astro
└── package.json
```

Astro looks for `.astro` or `.md` files in the `src/pages/` directory. Each page is exposed as a route based on its file name.

There's nothing special about `src/components/`, but that's where we like to put any Astro/React/Vue/Svelte/Preact components.

Any static assets, like images, can be placed in the `public/` directory.

## 🧞 Commands

All commands are run from the root of the project, from a terminal:

| Command | Action |
| :--------------------- | :------------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:3000` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro preview` |
| `npm run astro --help` | Get help using the Astro CLI |

## 👀 Want to learn more?

Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
21 changes: 21 additions & 0 deletions apps/examples/astro/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { defineConfig } from "astro/config";
import node from "@astrojs/node";
import auth from '@auth/astro'
import Github from '@auth/core/providers/github'
import { loadEnv } from 'vite'

const env = loadEnv(import.meta.env.MODE, process.cwd(), "")

// https://astro.build/config
export default defineConfig({
output: "server",
adapter: node({
mode: 'standalone'
}),
integrations: [auth({
providers: [Github({
clientId: env.GITHUB_ID,
clientSecret: env.GITHUB_SECRET
})]
})]
});
19 changes: 19 additions & 0 deletions apps/examples/astro/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@example/basics",
"type": "module",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@astrojs/node": "5.0.0",
"@auth/astro": "latest",
"@auth/core": "latest",
"astro": "2.1.0"
}
}
13 changes: 13 additions & 0 deletions apps/examples/astro/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions apps/examples/astro/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="astro/client" />
26 changes: 26 additions & 0 deletions apps/examples/astro/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
export interface Props {
title: string;
}

const { title } = Astro.props;
---

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="generator" content={Astro.generator} />
<title>{title}</title>
</head>
<body>
<slot/>
</body>
</html>
<style is:global>
html {
font-family: system-ui, sans-serif;
}
</style>
25 changes: 25 additions & 0 deletions apps/examples/astro/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
import Layout from '../layouts/Layout.astro';
import type { Session } from '@auth/core/types';
import { Auth, SignIn, SignOut } from '@auth/astro/components';
import { getSession } from '@auth/astro/server'
let session = await getSession(Astro.request);
---

<Layout title="Welcome to Astro Auth">
<Auth>
{(session: Session) =>
<main>
<h1>Astro + AuthJS</h1>
<p>
<a href="/protected">Protected Route</a>
</p>
<SignIn>Login</SignIn>
<SignOut>Logout</SignOut>
<p>
{session ? `Logged in as ${session.user?.name}` : 'Not logged in'}
</p>
</main>
}
</Auth>
</Layout>
19 changes: 19 additions & 0 deletions apps/examples/astro/src/pages/protected.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
import { getSession } from "@auth/astro/server"

let session = await getSession(Astro.request)

if (!session) return Astro.redirect("/")
---

<p>
Only logged in users can see this page.
</p>

<p>
Logged in as {session?.user?.name}
</p>

<p>
<a href="/">Home</a>
</p>
3 changes: 3 additions & 0 deletions apps/examples/astro/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "astro/tsconfigs/strict"
}
15 changes: 15 additions & 0 deletions docs/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,21 @@ const docusaurusConfig = {
includeExtension: false,
},
],
[
"docusaurus-plugin-typedoc",
{
...typedocConfig,
id: "astro",
plugin: ["./tyepdoc"],
entryPoints: ["index.ts", "client.ts", "server.ts", "components.d.ts"].map(
(e) => `../packages/frameworks-astro/${e}`
),
tsconfig: "../packages/frameworks-astro/tsconfig.json",
out: "reference/04-astro",
watch: process.env.TYPEDOC_WATCH,
includeExtension: false
},
],
],
}

Expand Down
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"dependencies": {
"@auth/core": "workspace:*",
"@auth/sveltekit": "workspace:*",
"@auth/astro": "workspace:*",
"@mdx-js/react": "1.6.22",
"@sapphire/docusaurus-plugin-npm2yarn2pnpm": "1.1.4",
"classnames": "^2.3.2",
Expand Down
15 changes: 15 additions & 0 deletions docs/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ module.exports = {
},
items: ["reference/solidstart/client", "reference/solidstart/protected"],
},
{
type: "category",
label: "@auth/astro",
link: { type: "doc", id: "reference/astro/modules/main" },
items: [
{ type: "autogenerated", dirName: "reference/04-astro/modules" },
{
type: "category",
label: "Reflections",
collapsed: true,
className: "reflection-category", // See src/index.css
items: [{ type: "autogenerated", dirName: "reference/04-astro" }],
},
],
},
{
type: "category",
label: "@auth/nextjs",
Expand Down
20 changes: 20 additions & 0 deletions packages/frameworks-astro/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<p align="center">
<br/>
<a href="https://authjs.dev" target="_blank"><img width="150px" src="https://authjs.dev/img/logo/logo-sm.png" /></a>
<h3 align="center">Astro Auth</a></h3>
<h4 align="center">Authentication for Astro.</h4>
<p align="center" style="align: center;">
<a href="https://npm.im/next-auth">
<img src="https://img.shields.io/badge/TypeScript-blue?style=flat-square" alt="TypeScript" />
</a>
<a href="https://npm.im/@auth/astro">
<img alt="npm" src="https://img.shields.io/npm/v/@auth/sveltekit?color=green&label=@auth/astro&style=flat-square">
</a>
<a href="https://www.npmtrends.com/@auth/sveltekit">
<img src="https://img.shields.io/npm/dm/@auth/sveltekit?label=%20downloads&style=flat-square" alt="Downloads" />
</a>
<a href="https://github.com/nextauthjs/next-auth/stargazers">
<img src="https://img.shields.io/github/stars/nextauthjs/next-auth?style=flat-square" alt="Github Stars" />
</a>
</p>
</p>
Loading