Skip to content

Commit af4e2d1

Browse files
aksharahegdeAkshara Hegdeatinux
authored
feat: added google as oauth provider (#3)
* feat - added google login under provider * feat - added google login under provider * feat - added google as auth provider * chore: simplify gitignore * chore: various improvements --------- Co-authored-by: Akshara Hegde <[email protected]> Co-authored-by: Sébastien Chopin <[email protected]>
1 parent cbc8b7a commit af4e2d1

File tree

15 files changed

+209
-20
lines changed

15 files changed

+209
-20
lines changed

.eslintrc.cjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
root: true,
3+
extends: [
4+
'@nuxt/eslint-config'
5+
],
6+
rules: {
7+
// Global
8+
semi: ['error', 'never'],
9+
quotes: ['error', 'single'],
10+
'quote-props': ['error', 'as-needed'],
11+
// Vue
12+
'vue/multi-word-component-names': 0,
13+
'vue/max-attributes-per-line': 'off',
14+
'vue/no-v-html': 0
15+
}
16+
}

.gitignore

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ coverage
3434
.nyc_output
3535

3636
# VSCode
37-
.vscode/*
38-
!.vscode/settings.json
39-
!.vscode/tasks.json
40-
!.vscode/launch.json
41-
!.vscode/extensions.json
42-
!.vscode/*.code-snippets
37+
.vscode
4338

4439
# Intellij idea
4540
*.iml

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ It can also be set using environment variables:
148148
Supported providers:
149149
- GitHub
150150
- Spotify
151+
- Google
152+
153+
You can add your favorite provider by creating a new file in [src/runtime/server/lib/oauth/](./src/runtime/server/lib/oauth/).
151154

152155
### Example
153156

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"dependencies": {
3333
"@nuxt/kit": "^3.8.1",
3434
"defu": "^6.1.3",
35+
"ofetch": "^1.3.3",
3536
"ohash": "^1.1.3"
3637
},
3738
"devDependencies": {

playground/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ NUXT_OAUTH_GITHUB_CLIENT_SECRET=
55
# Spotify OAuth
66
NUXT_OAUTH_SPOTIFY_CLIENT_ID=
77
NUXT_OAUTH_SPOTIFY_CLIENT_SECRET=
8+
# Google OAuth
9+
NUXT_OAUTH_GOOGLE_CLIENT_ID=
10+
NUXT_OAUTH_GOOGLE_CLIENT_SECRET=

playground/app.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ const { loggedIn, session, clear } = useUserSession()
2525
>
2626
Login with Spotify
2727
</UButton>
28+
<UButton
29+
v-if="!loggedIn || !session.user.google"
30+
to="/auth/google"
31+
icon="i-simple-icons-google"
32+
external
33+
color="gray"
34+
size="xs"
35+
>
36+
Login with Google
37+
</UButton>
2838
<UButton
2939
v-if="loggedIn"
3040
color="gray"

playground/auth.d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
declare module '#auth-utils' {
22
interface UserSession {
33
user: {
4-
spotify?: any
5-
github?: any
6-
}
7-
loggedInAt: number
4+
spotify?: any;
5+
github?: any;
6+
google?: any;
7+
};
8+
loggedInAt: number;
89
}
910
}

playground/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"private": true,
3-
"name": "my-module-playground",
3+
"name": "auth-utils-playground",
44
"type": "module",
55
"scripts": {
66
"dev": "nuxi dev",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default oauth.googleEventHandler({
2+
async onSuccess(event, { user }) {
3+
await setUserSession(event, {
4+
user: {
5+
google: user,
6+
},
7+
loggedInAt: Date.now()
8+
})
9+
10+
return sendRedirect(event, '/')
11+
}
12+
})

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)