Skip to content

Commit 62f9ef3

Browse files
feat: add SPA/vue quickstart (#835)
Co-authored-by: Tom Papiernik <[email protected]>
1 parent fe248c0 commit 62f9ef3

File tree

25 files changed

+22148
-36
lines changed

25 files changed

+22148
-36
lines changed

Makefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,26 @@ export GO111MODULE := on
44
export PATH := .bin:${PATH}
55

66
.PHONY: install
7-
install: code-examples/protect-page-login/nextjs/package-lock.json code-examples/protect-page-login/expressjs/package-lock.json package-lock.json
7+
install: code-examples/protect-page-login/nextjs/package-lock.json code-examples/protect-page-login/expressjs/package-lock.json package-lock.json code-examples/protect-page-login/go/go.sum code-examples/auth-api/expressjs/package-lock.json code-examples/protect-page-login/vue/package-lock.json code-examples/protect-page-login/flutter_web_redirect/pubspec.lock
88
cd code-examples/protect-page-login/nextjs && npm i
99
cd code-examples/protect-page-login/expressjs && npm i
1010
npm i
11+
cd code-examples/protect-page-login/flutter_web_redirect && flutter pub get
12+
cd code-examples/protect-page-login/go && go mod download && go build -o server
13+
cd code-examples/protect-page-login/php && composer install
14+
cd code-examples/auth-api/expressjs && npm i
15+
cd code-examples/protect-page-login/vue && npm i
1116

1217
.PHONY: build-examples
1318
build-examples:
14-
cd code-examples/protect-page-login/nextjs && npm run build;
19+
cd code-examples/protect-page-login/nextjs && npm run build
20+
cd code-examples/protect-page-login/flutter_web_redirect && flutter build web --web-renderer html
21+
cd code-examples/protect-page-login/vue && VUE_APP_API_URL=http://localhost:4007 VUE_APP_ORY_URL=http://localhost:3006 npm run build
1522

1623
.PHONY: test
1724
test: install build-examples .bin/ory
1825
./src/scripts/test.sh
1926

2027
.bin/ory: Makefile
21-
bash <(curl https://raw.githubusercontent.com/ory/meta/master/install.sh) -d -b .bin ory v0.1.22
28+
bash <(curl https://raw.githubusercontent.com/ory/meta/master/install.sh) -d -b .bin ory v0.1.33
2229
touch -a -m .bin/ory
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const express = require('express')
2+
const cors = require('cors')
3+
const { V0alpha2Api, Configuration } = require('@ory/client')
4+
5+
const app = express()
6+
7+
// highlight-start
8+
const ory = new V0alpha2Api(
9+
new Configuration({
10+
// Points to the local Ory API server (Ory TunneL).
11+
basePath: process.env.ORY_URL || 'http://localhost:4000',
12+
baseOptions: { withCredentials: true }
13+
})
14+
)
15+
// highlight-end
16+
17+
app.use(
18+
// highlight-start
19+
cors({
20+
origin: process.env.UI_URL || 'http://localhost:8080',
21+
credentials: true // <- Required for CORS to accept cookies and tokens.
22+
})
23+
// highlight-end
24+
)
25+
26+
app.use((req, res, next) => {
27+
// A simple middleware to authenticate the request.
28+
// highlight-start
29+
ory
30+
.toSession(
31+
undefined,
32+
// This is important - you need to forward the cookies (think of it as a token)
33+
// to Ory:
34+
req.headers.cookie
35+
)
36+
.then(({ data }) => {
37+
req.session = data
38+
next()
39+
})
40+
.catch(() => {
41+
res.status(401)
42+
res.json({ error: 'Unauthorized' })
43+
})
44+
// highlight-end
45+
})
46+
47+
app.get('/api/hello', (req, res) => {
48+
res.json({
49+
message: 'Hello from our API!',
50+
// highlight-start
51+
session_id: req.session.id,
52+
identity_traits: req.session.identity.traits
53+
// highlight-end
54+
})
55+
})
56+
57+
const port = process.env.PORT || 8081
58+
app.listen(port, () => {
59+
console.log(`Example app listening on port ${port}`)
60+
})

0 commit comments

Comments
 (0)