forked from sidebase/nuxt-auth-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path[...].ts
More file actions
70 lines (64 loc) · 2.68 KB
/
[...].ts
File metadata and controls
70 lines (64 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import CredentialsProvider from 'next-auth/providers/credentials';
import GithubProvider from 'next-auth/providers/github';
import { NuxtAuthHandler } from '#auth';
const { githubClientId, githubClientSecret } = useRuntimeConfig();
export default NuxtAuthHandler({
// secret needed to run nuxt-auth in production mode (used to encrypt data)
secret: 'my-secret',
providers: [
// @ts-ignore Import is exported on .default during SSR, so we need to call it this way. May be fixed via Vite at some point
GithubProvider.default({
clientId: githubClientId,
clientSecret: githubClientSecret,
}),
// @ts-ignore Import is exported on .default during SSR, so we need to call it this way. May be fixed via Vite at some point
CredentialsProvider.default({
// The name to display on the sign in form (e.g. 'Sign in with...')
name: 'Credentials',
// The credentials is used to generate a suitable form on the sign in page.
// You can specify whatever fields you are expecting to be submitted.
// e.g. domain, username, password, 2FA token, etc.
// You can pass any HTML attribute to the <input> tag through the object.
credentials: {
username: {
label: 'Username',
type: 'text',
placeholder: '(hint: jsmith)',
},
password: {
label: 'Password',
type: 'password',
placeholder: '(hint: hunter2)',
},
},
authorize(credentials: any) {
// You need to provide your own logic here that takes the credentials
// submitted and returns either a object representing a user or value
// that is false/null if the credentials are invalid.
// NOTE: THE BELOW LOGIC IS NOT SAFE OR PROPER FOR AUTHENTICATION!
const user = {
id: '1',
name: 'J Smith',
username: 'jsmith',
password: 'hunter2',
image: 'https://avatars.githubusercontent.com/u/25911230?v=4',
};
if (
credentials?.username === user.username &&
credentials?.password === user.password
) {
// Any object returned will be saved in `user` property of the JWT
return user;
} else {
// eslint-disable-next-line no-console
console.error(
'Warning: Malicious login attempt registered, bad credentials provided'
);
// If you return null then an error will be displayed advising the user to check their details.
return null;
// You can also Reject this callback with an Error thus the user will be sent to the error page with the error message as a query parameter
}
},
}),
],
});